Skip to content

Commit 436cb91

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 c98ef6e commit 436cb91

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
@@ -1852,6 +1852,11 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
18521852
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
18531853
}
18541854

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

0 commit comments

Comments
 (0)