Skip to content

Commit

Permalink
tests/types: fix test case TestUnmarshalToReusedObject
Browse files Browse the repository at this point in the history
- Add check for when an object is empty and unmarshalles JSON
  to be equal with the reused object.
  • Loading branch information
cmeon committed Nov 9, 2016
1 parent b2d8089 commit 75a7db5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 75a7db5

Please sign in to comment.