Skip to content

Commit

Permalink
Tests isolated in mergo_test package
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio committed Jul 18, 2020
1 parent 52aafb3 commit e8f744e
Show file tree
Hide file tree
Showing 31 changed files with 207 additions and 165 deletions.
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/imdario/mergo

go 1.13

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

import "testing"
import (
"testing"

"github.com/imdario/mergo"
)

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

st := &issue100s{}
if err := Map(st, m); err != nil {
if err := mergo.Map(st, m); err != nil {
t.Error(err)
}
}
8 changes: 6 additions & 2 deletions issue104_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mergo
package mergo_test

import (
"reflect"
"testing"

"github.com/imdario/mergo"
)

type Record struct {
Expand All @@ -23,7 +25,9 @@ func StructToRecord(in interface{}) *Record {
}
}

Map(&rec.Data, in)
if err := mergo.Map(&rec.Data, in); err != nil {
panic(err)
}
return &rec
}

Expand Down
6 changes: 4 additions & 2 deletions issue121_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mergo
package mergo_test

import (
"testing"

"github.com/imdario/mergo"
)

func TestIssue121WithSliceDeepCopy(t *testing.T) {
Expand All @@ -19,7 +21,7 @@ func TestIssue121WithSliceDeepCopy(t *testing.T) {
},
}

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

Expand Down
6 changes: 4 additions & 2 deletions issue123_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mergo
package mergo_test

import (
"testing"

"github.com/imdario/mergo"
)

func TestIssue123(t *testing.T) {
Expand All @@ -17,7 +19,7 @@ func TestIssue123(t *testing.T) {
}

// Expected behavior
if err := Merge(&dst, src, WithOverride); err != nil {
if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
t.Fatal(err)
}
testCases := []struct {
Expand Down
6 changes: 4 additions & 2 deletions issue125_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mergo
package mergo_test

import (
"encoding/json"
"testing"

"github.com/imdario/mergo"
)

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

if err := Merge(&something, defaultSettings, WithOverrideEmptySlice); err != nil {
if err := mergo.Merge(&something, defaultSettings, mergo.WithOverrideEmptySlice); err != nil {
t.Errorf("Error while merging: %s", err)
}

Expand Down
8 changes: 5 additions & 3 deletions issue129_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mergo
package mergo_test

import (
"testing"

"github.com/imdario/mergo"
)

func TestIssue129Boolean(t *testing.T) {
Expand All @@ -20,7 +22,7 @@ func TestIssue129Boolean(t *testing.T) {
}

// Standard behavior
if err := Merge(&dst, src); err != nil {
if err := mergo.Merge(&dst, src); err != nil {
t.Error(err)
}
if dst.A != true {
Expand All @@ -35,7 +37,7 @@ func TestIssue129Boolean(t *testing.T) {
A: false,
B: true,
}
if err := Merge(&dst, src, WithOverwriteWithEmptyValue); err != nil {
if err := mergo.Merge(&dst, src, mergo.WithOverwriteWithEmptyValue); err != nil {
t.Error(err)
}
if dst.A != true {
Expand Down
6 changes: 4 additions & 2 deletions issue131_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mergo
package mergo_test

import (
"testing"

"github.com/imdario/mergo"
)

type foz struct {
Expand All @@ -18,7 +20,7 @@ func TestIssue131MergeWithOverwriteWithEmptyValue(t *testing.T) {
A: func(v bool) *bool { return &v }(true),
B: "dest",
}
if err := Merge(&dest, src, WithOverwriteWithEmptyValue); err != nil {
if err := mergo.Merge(&dest, src, mergo.WithOverwriteWithEmptyValue); err != nil {
t.Error(err)
}
if *src.A != *dest.A {
Expand Down
20 changes: 13 additions & 7 deletions issue136_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mergo
package mergo_test

import (
"testing"

"github.com/imdario/mergo"
)

type embeddedTestA struct {
Expand All @@ -15,13 +17,17 @@ type embeddedTestB struct {
}

func TestMergeEmbedded(t *testing.T) {
a := &embeddedTestA{
"Suwon", 16,
}
var (
err error
a = &embeddedTestA{
"Suwon", 16,
}
b = &embeddedTestB{}
)

b := &embeddedTestB{}

err := Merge(&b.embeddedTestA, *a)
if err := mergo.Merge(&b.embeddedTestA, *a); err != nil {
t.Error(err)
}

if b.Name != "Suwon" {
t.Errorf("%v %v", b.Name, err)
Expand Down
8 changes: 5 additions & 3 deletions issue138_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mergo
package mergo_test

import (
"encoding/json"
"testing"

"github.com/imdario/mergo"
)

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

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

c := compatibleConfig{}
if err := Map(&c, foo); err != nil {
if err := mergo.Map(&c, foo); err != nil {
t.Error(err)
}
}
12 changes: 7 additions & 5 deletions issue143_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package mergo
package mergo_test

import (
"fmt"
"testing"

"github.com/imdario/mergo"
)

func TestIssue143(t *testing.T) {
testCases := []struct {
options []func(*Config)
options []func(*mergo.Config)
expected func(map[string]interface{}) error
}{
{
options: []func(*Config){WithOverride},
options: []func(*mergo.Config){mergo.WithOverride},
expected: func(m map[string]interface{}) error {
properties := m["properties"].(map[string]interface{})
if properties["field1"] != "wrong" {
Expand All @@ -21,7 +23,7 @@ func TestIssue143(t *testing.T) {
},
},
{
options: []func(*Config){},
options: []func(*mergo.Config){},
expected: func(m map[string]interface{}) error {
properties := m["properties"].(map[string]interface{})
if properties["field1"] == "wrong" {
Expand All @@ -40,7 +42,7 @@ func TestIssue143(t *testing.T) {
},
}

err := Map(
err := mergo.Map(
&base,
map[string]interface{}{
"properties": map[string]interface{}{
Expand Down
6 changes: 4 additions & 2 deletions issue149_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mergo
package mergo_test

import (
"testing"

"github.com/imdario/mergo"
)

type user struct {
Expand All @@ -25,7 +27,7 @@ func TestIssue149(t *testing.T) {
User: nil,
Token: &tokenValue,
}
if err := Merge(dest, src, WithOverwriteWithEmptyValue); err != nil {
if err := mergo.Merge(dest, src, mergo.WithOverwriteWithEmptyValue); err != nil {
t.Error(err)
}
if dest.User != nil {
Expand Down
6 changes: 4 additions & 2 deletions issue17_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mergo
package mergo_test

import (
"encoding/json"
"testing"

"github.com/imdario/mergo"
)

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

if err := MergeWithOverwrite(&something, maprequest); err != nil {
if err := mergo.MergeWithOverwrite(&something, maprequest); err != nil {
t.Errorf("Error while merging: %s", err)
}
}
6 changes: 4 additions & 2 deletions issue23_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mergo
package mergo_test

import (
"testing"
"time"

"github.com/imdario/mergo"
)

type document struct {
Expand All @@ -19,7 +21,7 @@ func TestIssue23MergeWithOverwrite(t *testing.T) {
&expected,
}

if err := MergeWithOverwrite(&dst, src); err != nil {
if err := mergo.MergeWithOverwrite(&dst, src); err != nil {
t.Errorf("Error while merging %s", err)
}

Expand Down
8 changes: 5 additions & 3 deletions issue33_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mergo
package mergo_test

import (
"testing"

"github.com/imdario/mergo"
)

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

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

Expand Down
Loading

0 comments on commit e8f744e

Please sign in to comment.