forked from darccio/mergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr180_test.go
56 lines (44 loc) · 1.1 KB
/
pr180_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
package mergo_test
import (
"encoding/json"
"fmt"
"testing"
"github.com/imdario/mergo"
)
func pp(i interface{}) string {
b, _ := json.MarshalIndent(i, "", " ")
return string(b)
}
func TestIssue121WithSliceDeepMerge(t *testing.T) {
dst := map[string]interface{}{
"a": "1",
"b": []map[string]interface{}{
{"c": "2"},
},
}
src := map[string]interface{}{
"b": []map[string]interface{}{
{"c": "3", "d": "1"},
{"e": "1", "f": "1", "g": []string{"1", "2"}},
},
}
if err := mergo.Merge(&dst, src, mergo.WithSliceDeepMerge); err != nil {
t.Fatalf("Error during the merge: %v", err)
}
fmt.Println(pp(dst))
if dst["a"].(string) != "1" {
t.Error("a should equal '1'")
}
if dst["b"].([]map[string]interface{})[0]["c"] != "2" {
t.Error("b.[0].c should equal '2'")
}
if dst["b"].([]map[string]interface{})[0]["d"] != "1" {
t.Error("b.[0].d should equal '2'")
}
if dst["b"].([]map[string]interface{})[1]["e"] != "1" {
t.Error("b.[1].e should equal '1'")
}
if dst["b"].([]map[string]interface{})[1]["g"].([]string)[0] != "1" {
t.Error("b.[1].g[0] should equal '1'")
}
}