Skip to content

Commit

Permalink
testing: proper error on invalid ExpectedResult
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Nov 7, 2016
1 parent 8f7d2b1 commit 5ce3ca6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ func RunTest(t *testing.T, test *Test) {
t.Fatal(err)
}

want := formatJSON([]byte(test.ExpectedResult))
var v interface{}
if err := json.Unmarshal([]byte(test.ExpectedResult), &v); err != nil {
t.Fatalf("invalid JSON for ExpectedResult: %s", err)
}
want, _ := json.Marshal(v)

if !bytes.Equal(got, want) {
t.Logf("want: %s", want)
t.Logf("got: %s", got)
t.Fail()
}
}

func formatJSON(data []byte) []byte {
var v interface{}
json.Unmarshal(data, &v)
b, _ := json.Marshal(v)
return b
}

0 comments on commit 5ce3ca6

Please sign in to comment.