EqualJSON asserts that two JSON strings are equal
(t *testing.T, a, b, message string)
| 109 | |
| 110 | // EqualJSON asserts that two JSON strings are equal |
| 111 | func 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 |