forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus_test.go
60 lines (56 loc) · 1.12 KB
/
status_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
package notification
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
)
func checkLvlPtr(l CheckLevel) *CheckLevel {
return &l
}
func TestStatusJSON(t *testing.T) {
cases := []struct {
name string
src StatusRule
target StatusRule
}{
{
name: "regular status rule",
src: StatusRule{
CurrentLevel: Warn,
PreviousLevel: checkLvlPtr(Critical),
},
target: StatusRule{
CurrentLevel: Warn,
PreviousLevel: checkLvlPtr(Critical),
},
},
{
name: "empty",
src: StatusRule{},
target: StatusRule{},
},
{
name: "invalid status",
src: StatusRule{
CurrentLevel: CheckLevel(-10),
},
target: StatusRule{
CurrentLevel: Unknown,
},
},
}
for _, c := range cases {
serialized, err := json.Marshal(c.src)
if err != nil {
t.Errorf("%s marshal failed, err: %s", c.name, err)
}
var got StatusRule
err = json.Unmarshal(serialized, &got)
if err != nil {
t.Errorf("%s unmarshal failed, err: %s", c.name, err)
}
if diff := cmp.Diff(got, c.target); diff != "" {
t.Errorf("status rules are different -got/+want\ndiff %s", diff)
}
}
}