Repository navigation
Expand file tree
/
Copy pathmerge_test.go
More file actions
93 lines (87 loc) · 1.51 KB
/
Copy pathmerge_test.go
File metadata and controls
93 lines (87 loc) · 1.51 KB
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
package variables
import (
"fmt"
"reflect"
"testing"
)
func TestMerge(t *testing.T) {
cases := []struct {
Name string
A, B map[string]interface{}
Expected map[string]interface{}
}{
{
"basic key/value",
map[string]interface{}{
"foo": "bar",
},
map[string]interface{}{
"bar": "baz",
},
map[string]interface{}{
"foo": "bar",
"bar": "baz",
},
},
{
"map unset",
map[string]interface{}{
"foo": "bar",
},
map[string]interface{}{
"bar": map[string]interface{}{
"foo": "bar",
},
},
map[string]interface{}{
"foo": "bar",
"bar": map[string]interface{}{
"foo": "bar",
},
},
},
{
"map merge",
map[string]interface{}{
"foo": "bar",
"bar": map[string]interface{}{
"bar": "baz",
},
},
map[string]interface{}{
"bar": map[string]interface{}{
"foo": "bar",
},
},
map[string]interface{}{
"foo": "bar",
"bar": map[string]interface{}{
"foo": "bar",
"bar": "baz",
},
},
},
{
"basic k/v with lists",
map[string]interface{}{
"foo": "bar",
"bar": []interface{}{"foo"},
},
map[string]interface{}{
"bar": []interface{}{"bar"},
},
map[string]interface{}{
"foo": "bar",
"bar": []interface{}{"bar"},
},
},
}
for i, tc := range cases {
t.Run(fmt.Sprintf("%d-%s", i, tc.Name), func(t *testing.T) {
actual := Merge(tc.A, tc.B)
if !reflect.DeepEqual(tc.Expected, actual) {
t.Fatalf("bad: %#v", actual)
}
})
}
}