cubefs

Форк
0
/
proxy_test.go 
72 строки · 2.0 Кб
1
// Copyright 2022 The CubeFS Authors.
2
//
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
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
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.
14

15
package proto
16

17
import (
18
	"encoding/json"
19
	"testing"
20

21
	"github.com/stretchr/testify/require"
22
)
23

24
func TestShardRepairMsg_IsValid(t *testing.T) {
25
	for _, cs := range []struct {
26
		msg ShardRepairMsg
27
		ok  bool
28
	}{
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},
33
	} {
34
		require.Equal(t, cs.ok, cs.msg.IsValid())
35
	}
36
}
37

38
func TestDeleteMsg_IsValid(t *testing.T) {
39
	msg := DeleteMsg{ClusterID: 1, Bid: 1, Vid: 1}
40
	require.Equal(t, true, msg.IsValid())
41

42
	msg = DeleteMsg{ClusterID: 1, Vid: 1}
43
	require.Equal(t, false, msg.IsValid())
44

45
	msg = DeleteMsg{ClusterID: 1, Bid: 1}
46
	require.Equal(t, false, msg.IsValid())
47
}
48

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())
54

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)
62

63
	msg := DeleteMsg{ClusterID: 1, Bid: 1}
64
	msg.SetDeleteStage(stags)
65
	b, err := json.Marshal(msg)
66
	require.NoError(t, err)
67

68
	var delMsg DeleteMsg
69
	err = json.Unmarshal(b, &delMsg)
70
	require.NoError(t, err)
71
	require.Equal(t, msg, delMsg)
72
}
73

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.