Skip to content
Merged
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
20 changes: 20 additions & 0 deletions netdeploy/networkTemplates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package netdeploy

import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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)
}