Skip to content

Commit e8f744e

Browse files
committed
Tests isolated in mergo_test package
1 parent 52aafb3 commit e8f744e

31 files changed

+207
-165
lines changed

go.mod

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ module github.com/imdario/mergo
22

33
go 1.13
44

5-
require (
6-
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6 // indirect
7-
gopkg.in/yaml.v2 v2.3.0
8-
)
5+
require gopkg.in/yaml.v2 v2.3.0

go.sum

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,4 @@
1-
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
2-
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
3-
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
4-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
6-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
7-
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
8-
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
9-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
10-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
11-
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
12-
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
13-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
14-
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
15-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
16-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
17-
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
18-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
19-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
20-
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6 h1:nULzSsKgihxFGLnQFv2T7lE5vIhOtg8ZPpJHapEt7o0=
21-
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
22-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
23-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
24-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
25-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
262
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
273
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
284
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

issue100_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
package mergo
1+
package mergo_test
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/imdario/mergo"
7+
)
48

59
type issue100s struct {
610
Member interface{}
@@ -11,7 +15,7 @@ func TestIssue100(t *testing.T) {
1115
m["Member"] = "anything"
1216

1317
st := &issue100s{}
14-
if err := Map(st, m); err != nil {
18+
if err := mergo.Map(st, m); err != nil {
1519
t.Error(err)
1620
}
1721
}

issue104_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"reflect"
55
"testing"
6+
7+
"github.com/imdario/mergo"
68
)
79

810
type Record struct {
@@ -23,7 +25,9 @@ func StructToRecord(in interface{}) *Record {
2325
}
2426
}
2527

26-
Map(&rec.Data, in)
28+
if err := mergo.Map(&rec.Data, in); err != nil {
29+
panic(err)
30+
}
2731
return &rec
2832
}
2933

issue121_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"testing"
5+
6+
"github.com/imdario/mergo"
57
)
68

79
func TestIssue121WithSliceDeepCopy(t *testing.T) {
@@ -19,7 +21,7 @@ func TestIssue121WithSliceDeepCopy(t *testing.T) {
1921
},
2022
}
2123

22-
if err := Merge(&dst, src, WithSliceDeepCopy); err != nil {
24+
if err := mergo.Merge(&dst, src, mergo.WithSliceDeepCopy); err != nil {
2325
t.Errorf("Error during the merge: %v", err)
2426
}
2527

issue123_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"testing"
5+
6+
"github.com/imdario/mergo"
57
)
68

79
func TestIssue123(t *testing.T) {
@@ -17,7 +19,7 @@ func TestIssue123(t *testing.T) {
1719
}
1820

1921
// Expected behavior
20-
if err := Merge(&dst, src, WithOverride); err != nil {
22+
if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
2123
t.Fatal(err)
2224
}
2325
testCases := []struct {

issue125_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"encoding/json"
55
"testing"
6+
7+
"github.com/imdario/mergo"
68
)
79

810
type settings struct {
@@ -24,7 +26,7 @@ func TestIssue125MergeWithOverwrite(t *testing.T) {
2426
t.Errorf("Error while Unmarshalling maprequest: %s", err)
2527
}
2628

27-
if err := Merge(&something, defaultSettings, WithOverrideEmptySlice); err != nil {
29+
if err := mergo.Merge(&something, defaultSettings, mergo.WithOverrideEmptySlice); err != nil {
2830
t.Errorf("Error while merging: %s", err)
2931
}
3032

issue129_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"testing"
5+
6+
"github.com/imdario/mergo"
57
)
68

79
func TestIssue129Boolean(t *testing.T) {
@@ -20,7 +22,7 @@ func TestIssue129Boolean(t *testing.T) {
2022
}
2123

2224
// Standard behavior
23-
if err := Merge(&dst, src); err != nil {
25+
if err := mergo.Merge(&dst, src); err != nil {
2426
t.Error(err)
2527
}
2628
if dst.A != true {
@@ -35,7 +37,7 @@ func TestIssue129Boolean(t *testing.T) {
3537
A: false,
3638
B: true,
3739
}
38-
if err := Merge(&dst, src, WithOverwriteWithEmptyValue); err != nil {
40+
if err := mergo.Merge(&dst, src, mergo.WithOverwriteWithEmptyValue); err != nil {
3941
t.Error(err)
4042
}
4143
if dst.A != true {

issue131_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"testing"
5+
6+
"github.com/imdario/mergo"
57
)
68

79
type foz struct {
@@ -18,7 +20,7 @@ func TestIssue131MergeWithOverwriteWithEmptyValue(t *testing.T) {
1820
A: func(v bool) *bool { return &v }(true),
1921
B: "dest",
2022
}
21-
if err := Merge(&dest, src, WithOverwriteWithEmptyValue); err != nil {
23+
if err := mergo.Merge(&dest, src, mergo.WithOverwriteWithEmptyValue); err != nil {
2224
t.Error(err)
2325
}
2426
if *src.A != *dest.A {

issue136_test.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"testing"
5+
6+
"github.com/imdario/mergo"
57
)
68

79
type embeddedTestA struct {
@@ -15,13 +17,17 @@ type embeddedTestB struct {
1517
}
1618

1719
func TestMergeEmbedded(t *testing.T) {
18-
a := &embeddedTestA{
19-
"Suwon", 16,
20-
}
20+
var (
21+
err error
22+
a = &embeddedTestA{
23+
"Suwon", 16,
24+
}
25+
b = &embeddedTestB{}
26+
)
2127

22-
b := &embeddedTestB{}
23-
24-
err := Merge(&b.embeddedTestA, *a)
28+
if err := mergo.Merge(&b.embeddedTestA, *a); err != nil {
29+
t.Error(err)
30+
}
2531

2632
if b.Name != "Suwon" {
2733
t.Errorf("%v %v", b.Name, err)

issue138_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"encoding/json"
55
"testing"
6+
7+
"github.com/imdario/mergo"
68
)
79

810
const issue138configuration string = `
@@ -24,7 +26,7 @@ func TestIssue138(t *testing.T) {
2426
// https://golang.org/pkg/encoding/json/#Unmarshal
2527
json.Unmarshal([]byte(issue138configuration), &foo)
2628

27-
err := Map(&config{}, foo)
29+
err := mergo.Map(&config{}, foo)
2830
if err == nil {
2931
t.Error("expected type mismatch error, got nil")
3032
} else {
@@ -34,7 +36,7 @@ func TestIssue138(t *testing.T) {
3436
}
3537

3638
c := compatibleConfig{}
37-
if err := Map(&c, foo); err != nil {
39+
if err := mergo.Map(&c, foo); err != nil {
3840
t.Error(err)
3941
}
4042
}

issue143_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"fmt"
55
"testing"
6+
7+
"github.com/imdario/mergo"
68
)
79

810
func TestIssue143(t *testing.T) {
911
testCases := []struct {
10-
options []func(*Config)
12+
options []func(*mergo.Config)
1113
expected func(map[string]interface{}) error
1214
}{
1315
{
14-
options: []func(*Config){WithOverride},
16+
options: []func(*mergo.Config){mergo.WithOverride},
1517
expected: func(m map[string]interface{}) error {
1618
properties := m["properties"].(map[string]interface{})
1719
if properties["field1"] != "wrong" {
@@ -21,7 +23,7 @@ func TestIssue143(t *testing.T) {
2123
},
2224
},
2325
{
24-
options: []func(*Config){},
26+
options: []func(*mergo.Config){},
2527
expected: func(m map[string]interface{}) error {
2628
properties := m["properties"].(map[string]interface{})
2729
if properties["field1"] == "wrong" {
@@ -40,7 +42,7 @@ func TestIssue143(t *testing.T) {
4042
},
4143
}
4244

43-
err := Map(
45+
err := mergo.Map(
4446
&base,
4547
map[string]interface{}{
4648
"properties": map[string]interface{}{

issue149_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"testing"
5+
6+
"github.com/imdario/mergo"
57
)
68

79
type user struct {
@@ -25,7 +27,7 @@ func TestIssue149(t *testing.T) {
2527
User: nil,
2628
Token: &tokenValue,
2729
}
28-
if err := Merge(dest, src, WithOverwriteWithEmptyValue); err != nil {
30+
if err := mergo.Merge(dest, src, mergo.WithOverwriteWithEmptyValue); err != nil {
2931
t.Error(err)
3032
}
3133
if dest.User != nil {

issue17_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"encoding/json"
55
"testing"
6+
7+
"github.com/imdario/mergo"
68
)
79

810
func TestIssue17MergeWithOverwrite(t *testing.T) {
@@ -20,7 +22,7 @@ func TestIssue17MergeWithOverwrite(t *testing.T) {
2022
t.Errorf("Error while Unmarshalling maprequest: %s", err)
2123
}
2224

23-
if err := MergeWithOverwrite(&something, maprequest); err != nil {
25+
if err := mergo.MergeWithOverwrite(&something, maprequest); err != nil {
2426
t.Errorf("Error while merging: %s", err)
2527
}
2628
}

issue23_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"testing"
55
"time"
6+
7+
"github.com/imdario/mergo"
68
)
79

810
type document struct {
@@ -19,7 +21,7 @@ func TestIssue23MergeWithOverwrite(t *testing.T) {
1921
&expected,
2022
}
2123

22-
if err := MergeWithOverwrite(&dst, src); err != nil {
24+
if err := mergo.MergeWithOverwrite(&dst, src); err != nil {
2325
t.Errorf("Error while merging %s", err)
2426
}
2527

issue33_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package mergo
1+
package mergo_test
22

33
import (
44
"testing"
5+
6+
"github.com/imdario/mergo"
57
)
68

79
type Foo struct {
@@ -16,7 +18,7 @@ func TestIssue33Merge(t *testing.T) {
1618
Bslice: []byte{1, 2},
1719
}
1820

19-
if err := Merge(&dest, toMerge); err != nil {
21+
if err := mergo.Merge(&dest, toMerge); err != nil {
2022
t.Errorf("Error while merging: %s", err)
2123
}
2224
// Merge doesn't overwrite an attribute if in destination it doesn't have a zero value.
@@ -25,7 +27,7 @@ func TestIssue33Merge(t *testing.T) {
2527
t.Errorf("dest.Str should have not been override as it has a non-zero value: dest.Str(%v) != 'a'", dest.Str)
2628
}
2729
// If we want to override, we must use MergeWithOverwrite or Merge using WithOverride.
28-
if err := Merge(&dest, toMerge, WithOverride); err != nil {
30+
if err := mergo.Merge(&dest, toMerge, mergo.WithOverride); err != nil {
2931
t.Errorf("Error while merging: %s", err)
3032
}
3133

0 commit comments

Comments
 (0)