1
// Copyright 2022 The CubeFS Authors.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
21
"github.com/stretchr/testify/require"
24
func TestShardRepairMsg_IsValid(t *testing.T) {
25
for _, cs := range []struct {
29
{ShardRepairMsg{1, 1, 1, []uint8{1}, 0, "access", ""}, true},
30
{ShardRepairMsg{1, 0, 1, []uint8{1}, 0, "access", ""}, false},
31
{ShardRepairMsg{1, 1, 0, []uint8{1}, 0, "access", ""}, false},
32
{ShardRepairMsg{1, 1, 1, []uint8{}, 0, "access", ""}, false},
34
require.Equal(t, cs.ok, cs.msg.IsValid())
38
func TestDeleteMsg_IsValid(t *testing.T) {
39
msg := DeleteMsg{ClusterID: 1, Bid: 1, Vid: 1}
40
require.Equal(t, true, msg.IsValid())
42
msg = DeleteMsg{ClusterID: 1, Vid: 1}
43
require.Equal(t, false, msg.IsValid())
45
msg = DeleteMsg{ClusterID: 1, Bid: 1}
46
require.Equal(t, false, msg.IsValid())
49
func TestMsgMarshal(t *testing.T) {
50
stags := BlobDeleteStage{}
51
stags.SetStage(1, DeleteStageMarkDelete)
52
stags.SetStage(2, DeleteStageMarkDelete)
53
require.Equal(t, stags, stags.Copy())
55
vuid, _ := NewVuid(1, 2, 1)
56
sg, exist := stags.Stage(vuid)
57
require.True(t, exist)
58
require.Equal(t, DeleteStageMarkDelete, sg)
59
vuid, _ = NewVuid(1, 10, 1)
60
_, exist = stags.Stage(vuid)
61
require.False(t, exist)
63
msg := DeleteMsg{ClusterID: 1, Bid: 1}
64
msg.SetDeleteStage(stags)
65
b, err := json.Marshal(msg)
66
require.NoError(t, err)
69
err = json.Unmarshal(b, &delMsg)
70
require.NoError(t, err)
71
require.Equal(t, msg, delMsg)