8000 assert.JSONEq: shortcut if same strings · stretchr/testify@2ac68b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ac68b9

Browse files
committed
assert.JSONEq: shortcut if same strings
Shortcut in assert.JSONEq once we have validated that 'expected' is valid JSON, and 'actual' is the exact same string.
1 parent 3c1541a commit 2ac68b9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

assert/assertions.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,11 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
18531853
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
18541854
}
18551855

1856+
// Shortcut if same bytes
1857+
if actual == expected {
1858+
return true
1859+
}
1860+
18561861
if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
18571862
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...)
18581863
}

0 commit comments

Comments
 (0)
0