Skip to content

Commit 4f71159

Browse files
committed
assert.YAMLEq: shortcut if same strings
Shortcut in assert.YAMLEq once we have validated that 'expected' is valid YAML, and 'actual' is the exact same string.
1 parent 4eb688b commit 4f71159

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
@@ -1876,6 +1876,11 @@ func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
18761876
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid yaml.\nYAML parsing error: '%s'", expected, err.Error()), msgAndArgs...)
18771877
}
18781878

1879+
// Shortcut if same bytes
1880+
if actual == expected {
1881+
return true
1882+
}
1883+
18791884
if err := yaml.Unmarshal([]byte(actual), &actualYAMLAsInterface); err != nil {
18801885
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid yaml.\nYAML error: '%s'", actual, err.Error()), msgAndArgs...)
18811886
}

0 commit comments

Comments
 (0)