Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from rusdevops/master
added WithOverrideEmptySlice config flag
- Loading branch information
Showing
2 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters