Skip to content

Commit

Permalink
Merge pull request #12 from divideandconquer/test-recursion
Browse files Browse the repository at this point in the history
Map Recursion issue
  • Loading branch information
darccio committed Apr 6, 2015
2 parents 96ac827 + 29dfa3f commit 63d3509
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion mergo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
package mergo

import (
"gopkg.in/yaml.v1"
"io/ioutil"
"reflect"
"testing"

"gopkg.in/yaml.v1"
)

type simpleTest struct {
Expand All @@ -36,6 +37,41 @@ type sliceTest struct {
S []int
}

func TestKb(t *testing.T) {
type testStruct struct {
Name string
KeyValue map[string]interface{}
}

akv := make(map[string]interface{})
akv["Key1"] = "not value 1"
akv["Key2"] = "value2"
a := testStruct{}
a.Name = "A"
a.KeyValue = akv

bkv := make(map[string]interface{})
bkv["Key1"] = "value1"
bkv["Key3"] = "value3"
b := testStruct{}
b.Name = "B"
b.KeyValue = bkv

ekv := make(map[string]interface{})
ekv["Key1"] = "not value 1"
ekv["Key2"] = "value2"
ekv["Key3"] = "value3"
expected := testStruct{}
expected.Name = "A"
expected.KeyValue = ekv

Merge(&b, a)

if !reflect.DeepEqual(b, expected) {
t.Errorf("Actual: %#v did not match \nExpected: %#v", b, expected)
}
}

func TestNil(t *testing.T) {
if err := Merge(nil, nil); err != ErrNilArguments {
t.Fail()
Expand Down

0 comments on commit 63d3509

Please sign in to comment.