Codebase list golang-github-imdario-mergo / c0bd9d15-5c14-408d-92dc-10704832b2fd/upstream/0.3.13+git20230113.1.12567bf issue17_test.go
c0bd9d15-5c14-408d-92dc-10704832b2fd/upstream/0.3.13+git20230113.1.12567bf

Tree @c0bd9d15-5c14-408d-92dc-10704832b2fd/upstream/0.3.13+git20230113.1.12567bf (Download .tar.gz)

issue17_test.go @c0bd9d15-5c14-408d-92dc-10704832b2fd/upstream/0.3.13+git20230113.1.12567bfraw · 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)
	}
}