Skip to content

Instantly share code, notes, and snippets.

@rajatjindal
Created March 28, 2018 05:13
Show Gist options
  • Save rajatjindal/35da5b59f7ba77d963f6191e7d910420 to your computer and use it in GitHub Desktop.
Save rajatjindal/35da5b59f7ba77d963f6191e7d910420 to your computer and use it in GitHub Desktop.
package mergo
import (
"encoding/json"
"reflect"
"testing"
)
var (
authinfo = `{
"name":"somename",
"exec": {
"command": "some-command",
"args": ["arg1", "arg2"],
"env": [
{
"name": "env1",
"value": "val1"
}
]
}
}`
)
func TestIssueNMergeWithOverwrite(t *testing.T) {
var authinfo1 map[string]interface{}
if err := json.Unmarshal([]byte(authinfo), &authinfo1); err != nil {
t.Errorf("Error while Unmarshalling maprequest: %s", err)
}
var authinfo2 map[string]interface{}
if err := json.Unmarshal([]byte(authinfo), &authinfo2); err != nil {
t.Errorf("Error while Unmarshalling maprequest: %s", err)
}
Merge(&authinfo1, authinfo2)
if !reflect.DeepEqual(authinfo1, authinfo2) {
t.Errorf("merging same maps result in dup values. \n\nAuthinfo1\n %#v \n Authinfo2\n %#v", authinfo1, authinfo2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment