Skip to content

Commit 3ba59b8

Browse files
committed
add ut
Signed-off-by: sivchari <[email protected]>
1 parent ed31e85 commit 3ba59b8

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

Diff for: pkg/utils/json/json_test.go

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package json
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func Test_removeFields(t *testing.T) {
9+
tests := []struct {
10+
name string
11+
config any
12+
live any
13+
want any
14+
}{
15+
{
16+
name: "map",
17+
config: map[string]any{
18+
"foo": "bar",
19+
},
20+
live: map[string]any{
21+
"foo": "baz",
22+
"bar": "baz",
23+
},
24+
want: map[string]any{
25+
"foo": "baz",
26+
},
27+
},
28+
{
29+
name: "nested map",
30+
config: map[string]any{
31+
"foo": map[string]any{
32+
"bar": "baz",
33+
},
34+
"bar": "baz",
35+
},
36+
live: map[string]any{
37+
"foo": map[string]any{
38+
"bar": "qux",
39+
"baz": "qux",
40+
},
41+
"bar": "baz",
42+
},
43+
want: map[string]any{
44+
"foo": map[string]any{
45+
"bar": "qux",
46+
},
47+
"bar": "baz",
48+
},
49+
},
50+
{
51+
name: "list",
52+
config: []any{
53+
map[string]any{
54+
"foo": "bar",
55+
},
56+
},
57+
live: []any{
58+
map[string]any{
59+
"foo": "baz",
60+
"bar": "baz",
61+
},
62+
},
63+
want: []any{
64+
map[string]any{
65+
"foo": "baz",
66+
},
67+
},
68+
},
69+
{
70+
name: "nested list",
71+
config: []any{
72+
map[string]any{
73+
"foo": map[string]any{
74+
"bar": "baz",
75+
},
76+
"bar": "baz",
77+
},
78+
},
79+
live: []any{
80+
map[string]any{
81+
"foo": map[string]any{
82+
"bar": "qux",
83+
"baz": "qux",
84+
},
85+
"bar": "baz",
86+
},
87+
},
88+
want: []any{
89+
map[string]any{
90+
"foo": map[string]any{
91+
"bar": "qux",
92+
},
93+
"bar": "baz",
94+
},
95+
},
96+
},
97+
}
98+
for _, tt := range tests {
99+
t.Run(tt.name, func(t *testing.T) {
100+
if got := removeFields(tt.config, tt.live); !reflect.DeepEqual(got, tt.want) {
101+
t.Errorf("removeFields() = %v, want %v", got, tt.want)
102+
}
103+
})
104+
}
105+
}

0 commit comments

Comments
 (0)