MCPcopy Index your code
hub / github.com/dnote/dnote / EqualJSON

Function EqualJSON

pkg/assert/assert.go:111–132  ·  view source on GitHub ↗

EqualJSON asserts that two JSON strings are equal

(t *testing.T, a, b, message string)

Source from the content-addressed store, hash-verified

109
110// EqualJSON asserts that two JSON strings are equal
111func EqualJSON(t *testing.T, a, b, message string) {
112 var o1 interface{}
113 var o2 interface{}
114
115 err := json.Unmarshal([]byte(a), &o1)
116 if err != nil {
117 panic(fmt.Errorf("Error mashalling string 1 :: %s", err.Error()))
118 }
119 err = json.Unmarshal([]byte(b), &o2)
120 if err != nil {
121 panic(fmt.Errorf("Error mashalling string 2 :: %s", err.Error()))
122 }
123
124 if reflect.DeepEqual(o1, o2) {
125 return
126 }
127
128 if len(message) == 0 {
129 message = fmt.Sprintf("%v != %v", a, b)
130 }
131 t.Errorf("%s.\nActual: %+v.\nExpected: %+v.", message, a, b)
132}
133
134// StatusCodeEquals asserts that the reponse's status code is equal to the
135// expected

Callers 1

TestMigrateToV7Function · 0.92

Calls 1

ErrorMethod · 0.45

Tested by 1

TestMigrateToV7Function · 0.74