package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMergeMap(t *testing.T) {
t.Run("case1", func(t *testing.T) {
m1 := map[string]interface{}{
"a": "1",
}
m2 := map[string]interface{}{
"b": "2",
}
got := MergeMap(m1, m2)
expect := map[string]interface{}{
"a": "1",
"b": "2",
}
assert.Equal(t, expect, got)
})
t.Run("case2", func(t *testing.T) {
m1 := map[string]interface{}{
"a": "1",
}
m2 := map[string]interface{}{
"b": map[string]interface{}{
"c": "2"},
}
m3 := map[string]interface{}{
"b": map[string]interface{}{
"d": "3"},
}
got := MergeMap(m1, m2, m3)
expect := map[string]interface{}{
"a": "1",
"b": map[string]interface{}{
"c": "2",
"d": "3",
},
}
assert.Equal(t, expect, got)
})
}
Try following case and it will fail