From 29dfa3f8804abd677f60f45f6738f40aec270f69 Mon Sep 17 00:00:00 2001 From: Kyle Boorky Date: Mon, 9 Mar 2015 15:16:40 -0400 Subject: [PATCH] adding failing recursion test. --- mergo_test.go | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/mergo_test.go b/mergo_test.go index 072bddb..e1df382 100644 --- a/mergo_test.go +++ b/mergo_test.go @@ -6,10 +6,11 @@ package mergo import ( - "gopkg.in/yaml.v1" "io/ioutil" "reflect" "testing" + + "gopkg.in/yaml.v1" ) type simpleTest struct { @@ -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()