Codebase list golang-github-imdario-mergo / 7deb9a0c-95ac-4160-873f-958ff2a9142a/upstream issue125_test.go
7deb9a0c-95ac-4160-873f-958ff2a9142a/upstream

Tree @7deb9a0c-95ac-4160-873f-958ff2a9142a/upstream (Download .tar.gz)

issue125_test.go @7deb9a0c-95ac-4160-873f-958ff2a9142a/upstream

0f692b0
3b4010a
 
 
 
 
0f692b0
3b4010a
 
 
 
 
 
 
 
0f692b0
 
 
 
 
 
 
 
3b4010a
 
 
 
0f692b0
 
3b4010a
 
0f692b0
3b4010a
 
 
0f692b0
3b4010a
 
 
 
package mergo_test

import (
	"encoding/json"
	"testing"

	"github.com/imdario/mergo"
)

type settings struct {
	FirstSlice  []string `json:"FirstSlice"`
	SecondSlice []string `json:"SecondSlice"`
}

func TestIssue125MergeWithOverwrite(t *testing.T) {
	var (
		defaultSettings = settings{
			FirstSlice:  []string{},
			SecondSlice: []string{},
		}
		something settings
		data      = `{"FirstSlice":[], "SecondSlice": null}`
	)

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

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

	if something.FirstSlice == nil {
		t.Error("Invalid merging first slice")
	}

	if something.SecondSlice == nil {
		t.Error("Invalid merging second slice")
	}
}