JSONEq asserts that two JSON strings are equivalent. assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
(t TestingT, expected string, actual string, msgAndArgs ...interface{})
| 1762 | // |
| 1763 | // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) |
| 1764 | func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { |
| 1765 | if h, ok := t.(tHelper); ok { |
| 1766 | h.Helper() |
| 1767 | } |
| 1768 | var expectedJSONAsInterface, actualJSONAsInterface interface{} |
| 1769 | |
| 1770 | if err := json.Unmarshal([]byte(expected), &expectedJSONAsInterface); err != nil { |
| 1771 | return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...) |
| 1772 | } |
| 1773 | |
| 1774 | if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil { |
| 1775 | return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...) |
| 1776 | } |
| 1777 | |
| 1778 | return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...) |
| 1779 | } |
| 1780 | |
| 1781 | func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) { |
| 1782 | t := reflect.TypeOf(v) |
searching dependent graphs…