forked from darccio/mergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue143_test.go
61 lines (57 loc) · 1.25 KB
/
issue143_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
package mergo_test
import (
"fmt"
"testing"
"github.com/imdario/mergo"
)
func TestIssue143(t *testing.T) {
testCases := []struct {
options []func(*mergo.Config)
expected func(map[string]interface{}) error
}{
{
options: []func(*mergo.Config){mergo.WithOverride},
expected: func(m map[string]interface{}) error {
properties := m["properties"].(map[string]interface{})
if properties["field1"] != "wrong" {
return fmt.Errorf("expected %q, got %v", "wrong", properties["field1"])
}
return nil
},
},
{
options: []func(*mergo.Config){},
expected: func(m map[string]interface{}) error {
properties := m["properties"].(map[string]interface{})
if properties["field1"] == "wrong" {
return fmt.Errorf("expected a map, got %v", "wrong")
}
return nil
},
},
}
for _, tC := range testCases {
base := map[string]interface{}{
"properties": map[string]interface{}{
"field1": map[string]interface{}{
"type": "text",
},
},
}
err := mergo.Map(
&base,
map[string]interface{}{
"properties": map[string]interface{}{
"field1": "wrong",
},
},
tC.options...,
)
if err != nil {
t.Error(err)
}
if err := tC.expected(base); err != nil {
t.Error(err)
}
}
}