sprig icon indicating copy to clipboard operation
sprig copied to clipboard

Merging with zero 0 does not work

Open sebastian-garn opened this issue 4 years ago • 4 comments

It seems like the value 0 is not merged properly. I have created the following test which currently fails.

func TestMergeZero(t *testing.T) {
	dict := map[string]interface{}{
		"src2": map[string]interface{}{
			"h": 10,
		},
		"src1": map[string]interface{}{
			"h": 0,
		},
		"dst": map[string]interface{}{},
	}
	tpl := `{{merge .dst .src1 .src2}}`
	_, err := runRaw(tpl, dict)
	if err != nil {
		t.Error(err)
	}
	expected := map[string]interface{}{
		"h": 0, // FAILS: I AM EXPECTING 0 BUT 10 IS WHAT I GET
	}
	assert.Equal(t, expected, dict["dst"])
}

Did I miss something?

sebastian-garn avatar Jul 01 '20 16:07 sebastian-garn

This appears to be the intended behavior. merge uses https://github.com/imdario/mergo under the hood which will overwrite zero values.

moorereason avatar Dec 09 '20 21:12 moorereason