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{})
| 1805 | // |
| 1806 | // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) |
| 1807 | func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { |
| 1808 | if h, ok := t.(tHelper); ok { |
| 1809 | h.Helper() |
| 1810 | } |
| 1811 | var expectedJSONAsInterface, actualJSONAsInterface interface{} |
| 1812 | |
| 1813 | if err := json.Unmarshal([]byte(expected), &expectedJSONAsInterface); err != nil { |
| 1814 | return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...) |
| 1815 | } |
| 1816 | |
| 1817 | if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil { |
| 1818 | return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...) |
| 1819 | } |
| 1820 | |
| 1821 | return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...) |
| 1822 | } |
| 1823 | |
| 1824 | // YAMLEq asserts that two YAML strings are equivalent. |
| 1825 | func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { |