Codebase list golang-github-imdario-mergo / 70a7923e-9f3d-41cc-9299-cc0b2bdef009/upstream/0.3.13+git20220917.2.c42713b issue17_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)

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

package mergo_test

import (
	"encoding/json"
	"testing"

	"github.com/imdario/mergo"
)

func TestIssue17MergeWithOverwrite(t *testing.T) {
	var (
		request    = `{"timestamp":null, "name": "foo"}`
		maprequest = map[string]interface{}{
			"timestamp": nil,
			"name":      "foo",
			"newStuff":  "foo",
		}
	)

	var something map[string]interface{}
	if err := json.Unmarshal([]byte(request), &something); err != nil {
		t.Errorf("Error while Unmarshalling maprequest: %s", err)
	}

	if err := mergo.MergeWithOverwrite(&something, maprequest); err != nil {
		t.Errorf("Error while merging: %s", err)
	}
}