Codebase list golang-github-imdario-mergo / 70a7923e-9f3d-41cc-9299-cc0b2bdef009/upstream/0.3.13+git20220917.2.c42713b issue90_test.go
70a7923e-9f3d-41cc-9299-cc0b2bdef009/upstream/0.3.13+git20220917.2.c42713b

Tree @70a7923e-9f3d-41cc-9299-cc0b2bdef009/upstream/0.3.13+git20220917.2.c42713b (Download .tar.gz)

issue90_test.go @70a7923e-9f3d-41cc-9299-cc0b2bdef009/upstream/0.3.13+git20220917.2.c42713braw · history · blame

package mergo_test

import (
	"github.com/imdario/mergo"
	"reflect"
	"testing"
)

type structWithStringMap struct {
	Data map[string]string
}

func TestIssue90(t *testing.T) {
	dst := map[string]structWithStringMap{
		"struct": {
			Data: nil,
		},
	}
	src := map[string]structWithStringMap{
		"struct": {
			Data: map[string]string{
				"foo": "bar",
			},
		},
	}
	expected := map[string]structWithStringMap{
		"struct": {
			Data: map[string]string{
				"foo": "bar",
			},
		},
	}

	err := mergo.Merge(&dst, src, mergo.WithOverride)
	if err != nil {
		t.Errorf("unexpected error %v", err)
	}

	if !reflect.DeepEqual(dst, expected) {
		t.Errorf("expected: %#v\ngot: %#v", expected, dst)
	}
}