forked from darccio/mergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue125_test.go
40 lines (32 loc) · 863 Bytes
/
issue125_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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")
}
}