This repository was archived by the owner on Feb 8, 2021. It is now read-only.
File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package util
18
18
19
19
import (
20
20
"encoding/json"
21
+ "reflect"
21
22
"testing"
22
23
23
24
"gopkg.in/v1/yaml"
@@ -171,6 +172,33 @@ func TestIntOrStringMarshalJSON(t *testing.T) {
171
172
}
172
173
}
173
174
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
+
174
202
func TestStringDiff (t * testing.T ) {
175
203
diff := StringDiff ("aaabb" , "aaacc" )
176
204
expect := "aaa\n \n A: bb\n \n B: cc\n \n "
You can’t perform that action at this time.
0 commit comments