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.
This commit is contained in:
Olivier Mengué 2025-05-28 19:11:19 +02:00
parent 4eb688ba0c
commit 4f71159ca8

View File

@ -1876,6 +1876,11 @@ func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid yaml.\nYAML parsing error: '%s'", expected, err.Error()), msgAndArgs...)
}
// Shortcut if same bytes
if actual == expected {
return true
}
if err := yaml.Unmarshal([]byte(actual), &actualYAMLAsInterface); err != nil {
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid yaml.\nYAML error: '%s'", actual, err.Error()), msgAndArgs...)
}