Merge pull request #977 from pmorie/unit

Add missing case for IntOrString unit tests
This commit is contained in:
brendandburns 2014-08-20 14:30:38 -07:00
commit 6ca912e07f

View File

@ -18,6 +18,7 @@ package util
import (
"encoding/json"
"reflect"
"testing"
"gopkg.in/v1/yaml"
@ -171,6 +172,33 @@ func TestIntOrStringMarshalJSON(t *testing.T) {
}
}
func TestIntOrStringMarshalJSONUnmarshalYAML(t *testing.T) {
cases := []struct {
input IntOrString
}{
{IntOrString{Kind: IntstrInt, IntVal: 123}},
{IntOrString{Kind: IntstrString, StrVal: "123"}},
}
for _, c := range cases {
input := IntOrStringHolder{c.input}
jsonMarshalled, err := json.Marshal(&input)
if err != nil {
t.Errorf("1: Failed to marshal input: '%v': %v", input, err)
}
var result IntOrStringHolder
err = yaml.Unmarshal(jsonMarshalled, &result)
if err != nil {
t.Errorf("2: Failed to unmarshall '%+v': %v", string(jsonMarshalled), err)
}
if !reflect.DeepEqual(input, result) {
t.Errorf("3: Failed to marshal input '%+v': got %+v", input, result)
}
}
}
func TestStringDiff(t *testing.T) {
diff := StringDiff("aaabb", "aaacc")
expect := "aaa\n\nA: bb\n\nB: cc\n\n"