Codebase list golang-github-imdario-mergo / b976f590-0d3e-4bdb-89f3-abe611355bc0/main issue17_test.go
b976f590-0d3e-4bdb-89f3-abe611355bc0/main

Tree @b976f590-0d3e-4bdb-89f3-abe611355bc0/main (Download .tar.gz)

issue17_test.go @b976f590-0d3e-4bdb-89f3-abe611355bc0/main

c9e3399
d415265
 
 
 
 
c9e3399
d415265
 
 
c9e3399
 
 
 
 
 
 
 
 
d415265
 
6720d30
d415265
c9e3399
 
6720d30
d415265
 
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)
	}
}