Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions conflate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type TestData struct {
All string `json:"all"`
}

type TestNulledData struct {
Foo string `yaml:"foo"`
Bar string `yaml:"bar"`
}

func TestFromFiles(t *testing.T) {
c, err := FromFiles("testdata/valid_parent.json")
assert.Nil(t, err)
Expand Down Expand Up @@ -361,3 +366,14 @@ func TestConflate_mergeDataError(t *testing.T) {
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "failed to merge")
}

func TestFromFilesNulled(t *testing.T) {
c, err := FromFiles("testdata/test_not_nulled.yaml", "testdata/test_nulled.yaml")
assert.Nil(t, err)
assert.NotNil(t, c)
var testData TestNulledData
err = c.Unmarshal(&testData)
assert.Nil(t, err)
assert.Equal(t, "foo", testData.Foo)
assert.Equal(t, "", testData.Bar)
}
5 changes: 5 additions & 0 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func mergeMapRecursive(ctx context, toData, fromData interface{}) error {
}

for name, fromProp := range fromProps {
// merge in explicit nil values
if fromProp == nil {
toProps[name] = nil
continue
}
if val := toProps[name]; val == nil {
toProps[name] = fromProp
} else {
Expand Down
2 changes: 2 additions & 0 deletions testdata/test_not_nulled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo: foo
bar: bar
2 changes: 2 additions & 0 deletions testdata/test_nulled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo: foo
bar: null