Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Merge function will not work properly if the map is nested #4

Open
hdw868 opened this issue Nov 24, 2021 · 0 comments
Open

The Merge function will not work properly if the map is nested #4

hdw868 opened this issue Nov 24, 2021 · 0 comments

Comments

@hdw868
Copy link

hdw868 commented Nov 24, 2021

Try following case and it will fail

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)
	})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant