forked from chyeh/nqm-agent
/
query_test.go
70 lines (61 loc) · 2.45 KB
/
query_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
package main
import (
"reflect"
"strings"
"testing"
"github.com/Cepave/common/model"
)
func TestUpdatedMsg(t *testing.T) {
testsOld := []map[string]model.MeasurementsProperty{
{"fping": {true, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
{"fping": {true, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {true, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
nil,
}
testsUpdated := []map[string]model.MeasurementsProperty{
{"fping": {false, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
{"fping": {true, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
nil,
{"fping": {true, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
}
expecteds := []string{
"<fping Disabled> <tcpping Disabled> <tcpconn Disabled> ",
"<fping Enabled> <tcpping Enabled> <tcpconn Enabled> ",
"<fping Disabled> ",
"<fping Disabled> <tcpconn Enabled> ",
"",
"<tcpping Disabled> <tcpconn Disabled> ",
"<fping Enabled> <tcpping Enabled> ",
}
for i, _ := range testsOld {
o := testsOld[i]
u := testsUpdated[i]
msg := updatedMsg(o, u)
msgSlice := strings.SplitAfter(msg, "> ")
msgMap := make(map[string]bool)
for _, m := range msgSlice {
if m == "" {
continue
}
msgMap[m] = true
}
expectedSlice := strings.SplitAfter(expecteds[i], "> ")
expectedMap := make(map[string]bool)
for _, m := range expectedSlice {
if m == "" {
continue
}
expectedMap[m] = true
}
if !reflect.DeepEqual(expectedMap, msgMap) {
t.Error(expectedMap, msgMap)
}
t.Log(msg)
}
}