-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathchange_test.go
75 lines (69 loc) · 1.46 KB
/
change_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package agollo
import (
"testing"
)
func TestChangeType(t *testing.T) {
var tps = []ChangeType{ADD, MODIFY, DELETE, ChangeType(-1)}
var strs = []string{"ADD", "MODIFY", "DELETE", "UNKNOW"}
for i, tp := range tps {
if tp.String() != strs[i] {
t.FailNow()
}
}
}
func TestMakeDeleteChange(t *testing.T) {
change := makeDeleteChange("key", "val")
t.Log(change.String())
if change.ChangeType != DELETE || change.OldValue != "val" {
t.FailNow()
}
}
func TestMakeModifyChange(t *testing.T) {
change := makeModifyChange("key", "old", "new")
t.Log(change.String())
if change.ChangeType != MODIFY || change.OldValue != "old" || change.NewValue != "new" {
t.FailNow()
}
}
func TestMakeAddChange(t *testing.T) {
change := makeAddChange("key", "value")
t.Log(change.String())
if change.ChangeType != ADD || change.NewValue != "value" {
t.FailNow()
}
}
func TestChangeEvent_String(t *testing.T) {
type fields struct {
Namespace string
Changes map[string]*Change
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "case1",
fields: fields{
Namespace: "application",
Changes: map[string]*Change{
"key": {
Key: "key",
ChangeType: ADD,
NewValue: "value",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &ChangeEvent{
Namespace: tt.fields.Namespace,
Changes: tt.fields.Changes,
}
got := e.String()
t.Log(got)
})
}
}