Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 5331cd6

Browse files
committed
Add missing case for IntOrString unit tests
1 parent a13edce commit 5331cd6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pkg/util/util_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package util
1818

1919
import (
2020
"encoding/json"
21+
"reflect"
2122
"testing"
2223

2324
"gopkg.in/v1/yaml"
@@ -171,6 +172,33 @@ func TestIntOrStringMarshalJSON(t *testing.T) {
171172
}
172173
}
173174

175+
func TestIntOrStringMarshalJSONUnmarshalYAML(t *testing.T) {
176+
cases := []struct {
177+
input IntOrString
178+
}{
179+
{IntOrString{Kind: IntstrInt, IntVal: 123}},
180+
{IntOrString{Kind: IntstrString, StrVal: "123"}},
181+
}
182+
183+
for _, c := range cases {
184+
input := IntOrStringHolder{c.input}
185+
jsonMarshalled, err := json.Marshal(&input)
186+
if err != nil {
187+
t.Errorf("1: Failed to marshal input: '%v': %v", input, err)
188+
}
189+
190+
var result IntOrStringHolder
191+
err = yaml.Unmarshal(jsonMarshalled, &result)
192+
if err != nil {
193+
t.Errorf("2: Failed to unmarshall '%+v': %v", string(jsonMarshalled), err)
194+
}
195+
196+
if !reflect.DeepEqual(input, result) {
197+
t.Errorf("3: Failed to marshal input '%+v': got %+v", input, result)
198+
}
199+
}
200+
}
201+
174202
func TestStringDiff(t *testing.T) {
175203
diff := StringDiff("aaabb", "aaacc")
176204
expect := "aaa\n\nA: bb\n\nB: cc\n\n"

0 commit comments

Comments
 (0)