forked from darccio/mergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v039_bugs_test.go
92 lines (83 loc) · 1.36 KB
/
v039_bugs_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
package mergo_test
import (
"testing"
"github.com/imdario/mergo"
)
type inner struct {
A int
}
type outer struct {
inner
B int
}
func TestV039Issue139(t *testing.T) {
dst := outer{
inner: inner{A: 1},
B: 2,
}
src := outer{
inner: inner{A: 10},
B: 20,
}
err := mergo.MergeWithOverwrite(&dst, src)
if err != nil {
panic(err.Error())
}
if dst.inner.A == 1 {
t.Errorf("expected %d, got %d", src.inner.A, dst.inner.A)
}
}
func TestV039Issue152(t *testing.T) {
dst := map[string]interface{}{
"properties": map[string]interface{}{
"field1": map[string]interface{}{
"type": "text",
},
"field2": "ohai",
},
}
src := map[string]interface{}{
"properties": map[string]interface{}{
"field1": "wrong",
},
}
if err := mergo.Map(&dst, src, mergo.WithOverride); err != nil {
t.Error(err)
}
}
type issue146Foo struct {
A string
B map[string]issue146Bar
}
type issue146Bar struct {
C *string
D *string
}
func TestV039Issue146(t *testing.T) {
var (
s1 = "asd"
s2 = "sdf"
)
dst := issue146Foo{
A: "two",
B: map[string]issue146Bar{
"foo": {
C: &s1,
},
},
}
src := issue146Foo{
A: "one",
B: map[string]issue146Bar{
"foo": {
D: &s2,
},
},
}
if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
t.Error(err)
}
if dst.B["foo"].D == nil {
t.Errorf("expected %v, got nil", &s2)
}
}