forked from darccio/mergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue89_test.go
57 lines (51 loc) · 916 Bytes
/
issue89_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
package mergo_test
import (
"testing"
"github.com/imdario/mergo"
)
func TestIssue89Boolean(t *testing.T) {
type Foo struct {
Bar bool `json:"bar"`
}
src := Foo{Bar: true}
dst := Foo{Bar: false}
if err := mergo.Merge(&dst, src); err != nil {
t.Error(err)
}
if dst.Bar == false {
t.Errorf("expected true, got false")
}
}
func TestIssue89MergeWithEmptyValue(t *testing.T) {
p1 := map[string]interface{}{
"A": 3, "B": "note", "C": true,
}
p2 := map[string]interface{}{
"B": "", "C": false,
}
if err := mergo.Merge(&p1, p2, mergo.WithOverwriteWithEmptyValue); err != nil {
t.Error(err)
}
testCases := []struct {
expected interface{}
key string
}{
{
3,
"A",
},
{
"",
"B",
},
{
false,
"C",
},
}
for _, tC := range testCases {
if p1[tC.key] != tC.expected {
t.Errorf("expected %v in p1[%q], got %v", tC.expected, tC.key, p1[tC.key])
}
}
}