-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrecord_test.go
75 lines (64 loc) · 1.4 KB
/
record_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 gohelix
import "testing"
func getTestRecord() []byte {
return []byte(`
{
"id":"BizProfile"
,"simpleFields":{
"STATE_MODEL_FACTORY_NAME":"DEFAULT"
,"BATCH_MESSAGE_MODE":"false"
,"SESSION_ID":"74bb9ce9cd90df5"
,"BUCKET_SIZE":"0"
,"STATE_MODEL_DEF":"OnlineOffline"
}
,"listFields":{
}
,"mapFields":{
"partition1":{
"CURRENT_STATE":"ONLINE"
}
,"partition2":{
"CURRENT_STATE":"ONLINE"
}
}
}
`)
}
func TestGetMapField(t *testing.T) {
t.Parallel()
data := getTestRecord()
r, err := NewRecordFromBytes(data)
if err != nil {
t.Error("panic")
}
state := r.GetMapField("partition1", "CURRENT_STATE")
if state != "ONLINE" {
t.Error("wrong result")
}
}
func TestSetMapField(t *testing.T) {
t.Parallel()
data := getTestRecord()
r, err := NewRecordFromBytes(data)
if err != nil {
t.Error("panic")
}
targetState := "OFFLINE"
r.SetMapField("partition1", "CURRENT_STATE", targetState)
state := r.GetMapField("partition1", "CURRENT_STATE")
if state != targetState {
t.Error("wrong result")
}
// set a new property
r.SetMapField("partition1", "INFO", "information")
info := r.GetMapField("partition1", "INFO")
if info != "information" {
t.Error("failed")
}
// set a new key
r.SetMapField("partition3", "CURRENT_STATE", "OFFLINE")
state = r.GetMapField("partition3", "CURRENT_STATE")
if state != "OFFLINE" {
t.Error("failed")
}
}