...
1 package mergo_test
2
3 import (
4 "testing"
5
6 "dario.cat/mergo"
7 )
8
9 type inner struct {
10 A int
11 }
12
13 type outer struct {
14 inner
15 B int
16 }
17
18 func TestV039Issue139(t *testing.T) {
19 dst := outer{
20 inner: inner{A: 1},
21 B: 2,
22 }
23 src := outer{
24 inner: inner{A: 10},
25 B: 20,
26 }
27 err := mergo.MergeWithOverwrite(&dst, src)
28 if err != nil {
29 panic(err.Error())
30 }
31 if dst.inner.A == 1 {
32 t.Errorf("expected %d, got %d", src.inner.A, dst.inner.A)
33 }
34 }
35
36 func TestV039Issue152(t *testing.T) {
37 dst := map[string]interface{}{
38 "properties": map[string]interface{}{
39 "field1": map[string]interface{}{
40 "type": "text",
41 },
42 "field2": "ohai",
43 },
44 }
45 src := map[string]interface{}{
46 "properties": map[string]interface{}{
47 "field1": "wrong",
48 },
49 }
50 if err := mergo.Map(&dst, src, mergo.WithOverride); err != nil {
51 t.Error(err)
52 }
53 }
54
55 type issue146Foo struct {
56 B map[string]issue146Bar
57 A string
58 }
59
60 type issue146Bar struct {
61 C *string
62 D *string
63 }
64
65 func TestV039Issue146(t *testing.T) {
66 var (
67 s1 = "asd"
68 s2 = "sdf"
69 )
70 dst := issue146Foo{
71 A: "two",
72 B: map[string]issue146Bar{
73 "foo": {
74 C: &s1,
75 },
76 },
77 }
78 src := issue146Foo{
79 A: "one",
80 B: map[string]issue146Bar{
81 "foo": {
82 D: &s2,
83 },
84 },
85 }
86 if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
87 t.Error(err)
88 }
89 if dst.B["foo"].D == nil {
90 t.Errorf("expected %v, got nil", &s2)
91 }
92 }
93
View as plain text