File: serializer_test.go

package info (click to toggle)
golang-github-smartystreets-assertions 1.6.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 340 kB
  • ctags: 431
  • sloc: python: 80; makefile: 19
file content (36 lines) | stat: -rw-r--r-- 967 bytes parent folder | download | duplicates (5)
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
package assertions

import (
	"encoding/json"
	"fmt"
	"testing"
)

func TestSerializerCreatesSerializedVersionOfAssertionResult(t *testing.T) {
	thing1 := Thing1{"Hi"}
	thing2 := Thing2{"Bye"}
	message := "Super-hip failure message."
	serializer := newSerializer()

	actualResult := serializer.serialize(thing1, thing2, message)

	expectedResult, _ := json.Marshal(FailureView{
		Message:  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:  message,
		Expected: fmt.Sprintf("%#v", thing1),
		Actual:   fmt.Sprintf("%#v", thing2),
	})
	if actualResult != string(expectedResult) {
		t.Errorf("\nExpected: %s\nActual:   %s", string(expectedResult), actualResult)
	}
}