diff --git a/assert/assertion_format.go b/assert/assertion_format.go index 190634165..66a9ecd00 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -456,6 +456,16 @@ func JSONEqf(t TestingT, expected string, actual string, msg string, args ...int return JSONEq(t, expected, actual, append([]interface{}{msg}, args...)...) } +// JSONEqBytesf asserts that two JSON byte slices are equivalent. +// +// assert.JSONEqBytesf(t, []byte(`{"hello": "world", "foo": "bar"}`), []byte(`{"foo": "bar", "hello": "world"}`), "error message %s", "formatted") +func JSONEqBytesf(t TestingT, expected []byte, actual []byte, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return JSONEqBytes(t, expected, actual, append([]interface{}{msg}, args...)...) +} + // Lenf asserts that the specified object has specific length. // Lenf also fails if the object has a type that len() not accept. // diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index 21629087b..a85b692cc 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -894,6 +894,26 @@ func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interf return JSONEq(a.t, expected, actual, msgAndArgs...) } +// JSONEqBytes asserts that two JSON byte slices are equivalent. +// +// a.JSONEqBytes([]byte(`{"hello": "world", "foo": "bar"}`), []byte(`{"foo": "bar", "hello": "world"}`)) +func (a *Assertions) JSONEqBytes(expected []byte, actual []byte, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return JSONEqBytes(a.t, expected, actual, msgAndArgs...) +} + +// JSONEqBytesf asserts that two JSON byte slices are equivalent. +// +// a.JSONEqBytesf([]byte(`{"hello": "world", "foo": "bar"}`), []byte(`{"foo": "bar", "hello": "world"}`), "error message %s", "formatted") +func (a *Assertions) JSONEqBytesf(expected []byte, actual []byte, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return JSONEqBytesf(a.t, expected, actual, msg, args...) +} + // JSONEqf asserts that two JSON strings are equivalent. // // a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") diff --git a/require/require.go b/require/require.go index d8921950d..20960c2ab 100644 --- a/require/require.go +++ b/require/require.go @@ -1132,6 +1132,32 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ t.FailNow() } +// JSONEqBytes asserts that two JSON byte slices are equivalent. +// +// assert.JSONEqBytes(t, []byte(`{"hello": "world", "foo": "bar"}`), []byte(`{"foo": "bar", "hello": "world"}`)) +func JSONEqBytes(t TestingT, expected []byte, actual []byte, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.JSONEqBytes(t, expected, actual, msgAndArgs...) { + return + } + t.FailNow() +} + +// JSONEqBytesf asserts that two JSON byte slices are equivalent. +// +// assert.JSONEqBytesf(t, []byte(`{"hello": "world", "foo": "bar"}`), []byte(`{"foo": "bar", "hello": "world"}`), "error message %s", "formatted") +func JSONEqBytesf(t TestingT, expected []byte, actual []byte, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.JSONEqBytesf(t, expected, actual, msg, args...) { + return + } + t.FailNow() +} + // JSONEqf asserts that two JSON strings are equivalent. // // require.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") diff --git a/require/require_forward.go b/require/require_forward.go index 1bd87304f..4ee8df46d 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -895,6 +895,26 @@ func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interf JSONEq(a.t, expected, actual, msgAndArgs...) } +// JSONEqBytes asserts that two JSON byte slices are equivalent. +// +// a.JSONEqBytes([]byte(`{"hello": "world", "foo": "bar"}`), []byte(`{"foo": "bar", "hello": "world"}`)) +func (a *Assertions) JSONEqBytes(expected []byte, actual []byte, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + JSONEqBytes(a.t, expected, actual, msgAndArgs...) +} + +// JSONEqBytesf asserts that two JSON byte slices are equivalent. +// +// a.JSONEqBytesf([]byte(`{"hello": "world", "foo": "bar"}`), []byte(`{"foo": "bar", "hello": "world"}`), "error message %s", "formatted") +func (a *Assertions) JSONEqBytesf(expected []byte, actual []byte, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + JSONEqBytesf(a.t, expected, actual, msg, args...) +} + // JSONEqf asserts that two JSON strings are equivalent. // // a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")