Skip to content

Commit

Permalink
fix with deep nested
Browse files Browse the repository at this point in the history
  • Loading branch information
barockok committed Jul 12, 2017
1 parent 5c04da6 commit dab2195
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions merge_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func Test_mergeDestFromJson(t *testing.T) {
"nestedAttr" : {
"attrLevel1" : "hello"
},
"deepNestedArrayWithPresentAttr" : {
"item1" : {
"attr1" : "hello"
}
},
"objectInArray" : [
{
"name" : "I'm so deep",
Expand Down Expand Up @@ -73,4 +78,15 @@ func Test_mergeDestFromJson(t *testing.T) {
if dest["newAttr"] != toI("hello") {
t.Errorf("Error, cannot add new attribute")
}
item1 := toI(map[string]interface{}{"attr2": "whadup"})
src["deepNestedArrayWithPresentAttr"] = toI(map[string]interface{}{"item1": item1})
mergeMap(dest, src)

item1onDest := dest["deepNestedArrayWithPresentAttr"].(map[string]interface{})["item1"].(map[string]interface{})
if item1onDest["attr2"] != toI("whadup") {
t.Errorf("Error, on deep nested wont add new attr")
}
if item1onDest["attr1"] != toI("hello") {
t.Errorf("Error, on deep nested it cange the existing value")
}
}

0 comments on commit dab2195

Please sign in to comment.