From 75a7db58791f5c210559f57ee2e4df86aaf348f4 Mon Sep 17 00:00:00 2001 From: Simeon Mugisha Date: Wed, 9 Nov 2016 14:52:29 +0800 Subject: [PATCH] tests/types: fix test case TestUnmarshalToReusedObject - Add check for when an object is empty and unmarshalles JSON to be equal with the reused object. --- tests/types/types_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/types/types_test.go b/tests/types/types_test.go index ea0e828..e9f6ed6 100644 --- a/tests/types/types_test.go +++ b/tests/types/types_test.go @@ -169,14 +169,23 @@ func TestUnmarshalToReusedObject(t *testing.T) { var record ff.Everything err := record.UnmarshalJSON([]byte(JSONWhole)) if err != nil { - t.Errorf("%v", err) + t.Errorf("UnmarshalJSON: %v", err) } for _, part := range JSONParts { reuseRecord := record reuseRecord.UnmarshalJSON([]byte("{" + part + "}")) if reflect.DeepEqual(record, reuseRecord) { - t.Errorf("%v should not be equal to %v\nrecord = %v\nreuseRecord = %v", JSONWhole, part, record, reuseRecord) + t.Fatalf("UnmarshalJSON: %v", err) + } + + var emptyRecord ff.Everything + if err := emptyRecord.UnmarshalJSON([]byte("{" + part + "}")); err != nil { + t.Fatalf("UnmarshalJSON: %v", err) + } + + if !reflect.DeepEqual(reuseRecord, emptyRecord) { + t.Errorf("%#v should be equal to %#v", reuseRecord, emptyRecord) } } }