diff --git a/netdeploy/networkTemplates_test.go b/netdeploy/networkTemplates_test.go index f8e3ee6857..31c85d6001 100644 --- a/netdeploy/networkTemplates_test.go +++ b/netdeploy/networkTemplates_test.go @@ -17,8 +17,10 @@ package netdeploy import ( + "encoding/json" "os" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/require" @@ -95,3 +97,21 @@ func TestValidate(t *testing.T) { err = template.Validate() a.NoError(err) } + +type overlayTestStruct struct { + A string + B string +} + +// TestJsonOverlay ensures that encoding/json will only clobber fields present in the json and leave other fields unchanged +func TestJsonOverlay(t *testing.T) { + before := overlayTestStruct{A: "one", B: "two"} + setB := "{\"B\":\"other\"}" + dec := json.NewDecoder(strings.NewReader(setB)) + after := before + err := dec.Decode(&after) + a := require.New(t) + a.NoError(err) + a.Equal("one", after.A) + a.Equal("other", after.B) +}