...

Source file src/github.com/imdario/mergo/issue17_test.go

Documentation: github.com/imdario/mergo

     1  package mergo_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/imdario/mergo"
     8  )
     9  
    10  func TestIssue17MergeWithOverwrite(t *testing.T) {
    11  	var (
    12  		request    = `{"timestamp":null, "name": "foo"}`
    13  		maprequest = map[string]interface{}{
    14  			"timestamp": nil,
    15  			"name":      "foo",
    16  			"newStuff":  "foo",
    17  		}
    18  	)
    19  
    20  	var something map[string]interface{}
    21  	if err := json.Unmarshal([]byte(request), &something); err != nil {
    22  		t.Errorf("Error while Unmarshalling maprequest: %s", err)
    23  	}
    24  
    25  	if err := mergo.MergeWithOverwrite(&something, maprequest); err != nil {
    26  		t.Errorf("Error while merging: %s", err)
    27  	}
    28  }
    29  

View as plain text