From a2513eb1d6440482726a28f1c74d179d9d58546b Mon Sep 17 00:00:00 2001 From: Meir Fischer Date: Thu, 26 Jun 2014 19:18:26 -0400 Subject: [PATCH] Test rejection of bad JSON. --- pkg/api/helper_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/api/helper_test.go b/pkg/api/helper_test.go index 8c8e6f04d3e..6eb9f93188e 100644 --- a/pkg/api/helper_test.go +++ b/pkg/api/helper_test.go @@ -113,4 +113,17 @@ func TestPtr(t *testing.T) { } } -// TODO: test rejection of bad JSON. +func TestBadJSONRejection(t *testing.T) { + badJSONMissingKind := []byte(`{ }`) + if _, err := Decode(badJSONMissingKind); err == nil { + t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind) + } + badJSONUnknownType := []byte(`{"kind": "bar"}`) + if _, err1 := Decode(badJSONUnknownType); err1 == nil { + t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType) + } + badJSONKindMismatch := []byte(`{"kind": "Pod"}`) + if err2 := DecodeInto(badJSONKindMismatch, &Minion{}); err2 == nil { + t.Errorf("Kind is set but doesn't match the object type: %s", badJSONKindMismatch) + } +}