Skip to content

Commit

Permalink
added test case for issue #125
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyacheslav.Vershinin authored and Vyacheslav.Vershinin committed Sep 24, 2019
1 parent 3d62192 commit bee5429
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions issue125_test.go
@@ -0,0 +1,37 @@
package mergo

import (
"encoding/json"
"testing"
)

var (
data = `{"FirstSlice":[], "SecondSlice": null}`
)

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

func TestIssue125MergeWithOverwrite(t *testing.T) {

defaultSettings := settings{
FirstSlice: []string{},
SecondSlice: []string{},
}

var something settings
if err := json.Unmarshal([]byte(data), &something); err != nil {
t.Errorf("Error while Unmarshalling maprequest: %s", err)
}
if err := Merge(&something, defaultSettings, 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")
}
}

0 comments on commit bee5429

Please sign in to comment.