-
Notifications
You must be signed in to change notification settings - Fork 36
/
serializer_test.go
52 lines (44 loc) · 1.53 KB
/
serializer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package assertions
import (
"encoding/json"
"fmt"
"testing"
)
func TestFailureSerializerCreatesSerializedVersionOfAssertionResult(t *testing.T) {
thing1 := Thing1{"Hi"}
thing2 := Thing2{"Bye"}
message := "Super-hip failure message. Diff: Something that we don't need."
serializer := newSerializer()
actualResult := serializer.serialize(thing1, thing2, message)
expectedResult, _ := json.Marshal(FailureView{
Message: "Super-hip failure message.",
Expected: fmt.Sprintf("%+v", thing1),
Actual: fmt.Sprintf("%+v", thing2),
})
if actualResult != string(expectedResult) {
t.Errorf("\nExpected: %s\nActual: %s", string(expectedResult), actualResult)
}
actualResult = serializer.serializeDetailed(thing1, thing2, message)
expectedResult, _ = json.Marshal(FailureView{
Message: "Super-hip failure message.",
Expected: fmt.Sprintf("%#v", thing1),
Actual: fmt.Sprintf("%#v", thing2),
})
if actualResult != string(expectedResult) {
t.Errorf("\nExpected: %s\nActual: %s", string(expectedResult), actualResult)
}
}
func TestNoopSerializerJustReturnsTheMessageInAllCases(t *testing.T) {
thing1 := Thing1{"Hi"}
thing2 := Thing2{"Bye"}
expected := "Super-hip failure message."
serializer := &noopSerializer{}
actual := serializer.serialize(thing1, thing2, expected)
if actual != expected {
t.Errorf("\nExpected: %s\nActual: %s", string(expected), actual)
}
actual = serializer.serializeDetailed(thing1, thing2, expected)
if actual != expected {
t.Errorf("\nExpected: %s\nActual: %s", string(expected), actual)
}
}