-
Notifications
You must be signed in to change notification settings - Fork 0
/
body_test.go
96 lines (87 loc) · 2.36 KB
/
body_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package bacom
import (
"strings"
"testing"
)
func TestCompare(t *testing.T) {
report, err := Compare(nil, nil, false, nil, nil)
if err != nil {
t.Errorf("Compare(nil, nil, false, nil, nil): unexpected error: %s", err)
}
if len(report) != 0 {
t.Errorf(
"Compare(nil, nil, false, nil, nil): unexpected report:\n%s\n",
strings.Join(report, "\n"),
)
}
mapA := map[string]interface{}{
"foo": "bar",
"fizz": []interface{}{42},
"buzz": 84,
}
mapB := map[string]interface{}{
"foo": "bar",
"fizz": 23,
}
mapC := map[string]interface{}{
"foo": "bar",
"fizz": 23,
"buzz": nil,
}
recMap := map[string]interface{}{}
recMap["foo"] = recMap
report, err = Compare(nil, nil, false, mapA, mapA)
if err != nil {
t.Errorf("Compare(nil, nil, false, mapA, mapA): unexpected error: %s", err)
}
if len(report) != 0 {
t.Errorf(
"Compare(nil, nil, false, mapA, mapA): unexpected report:\n%s\n",
strings.Join(report, "\n"),
)
}
report, err = Compare(nil, nil, false, mapA, mapB)
if err != nil {
t.Errorf("Compare(nil, nil, false, mapA, mapB): unexpected error: %s", err)
}
if len(report) != 2 {
t.Errorf(
"Compare(nil, nil, false, mapA, mapB): unexpected report length (should be 2 lines): %d",
len(report),
)
}
report, err = Compare([]string{".fizz"}, nil, false, mapA, mapB)
if err != nil {
t.Errorf("Compare(%q, nil, false, mapA, mapB): unexpected error: %s", []string{".fizz"}, err)
}
if len(report) != 1 {
t.Errorf(
"Compare(%q, nil, false, mapA, mapB): unexpected report length (should be 1 line): %d",
[]string{".fizz"}, len(report),
)
}
report, err = Compare(nil, []string{".buzz"}, false, mapA, mapB)
if err != nil {
t.Errorf("Compare(nil, %q, false, mapA, mapB): unexpected error: %s", []string{".buzz"}, err)
}
if len(report) != 1 {
t.Errorf(
"Compare(nil, %q, false, mapA, mapB): unexpected report length (should be 1 line): %d",
[]string{".buzz"}, len(report),
)
}
report, err = Compare(nil, nil, true, mapA, mapC)
if err != nil {
t.Errorf("Compare(nil, nil, true, mapA, mapC): unexpected error: %s", err)
}
if len(report) != 1 {
t.Errorf(
"Compare(nil, nil, true, mapA, mapC): unexpected report length (should be 1 lines): %d",
len(report),
)
}
_, err = Compare(nil, nil, false, recMap, mapA)
if err == nil {
t.Errorf("Compare(nil, nil, false, recMap, mapA): expected error, got nil")
}
}