MCPcopy
hub / github.com/stretchr/testify / EqualError

Function EqualError

assert/assertions.go:1664–1680  ·  view source on GitHub ↗

EqualError asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error. actualObj, err := SomeFunction() assert.EqualError(t, err, expectedErrorString)

(t TestingT, theError error, errString string, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

1662// actualObj, err := SomeFunction()
1663// assert.EqualError(t, err, expectedErrorString)
1664func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool {
1665 if h, ok := t.(tHelper); ok {
1666 h.Helper()
1667 }
1668 if !Error(t, theError, msgAndArgs...) {
1669 return false
1670 }
1671 expected := errString
1672 actual := theError.Error()
1673 // don't need to use deep equals here, we know they are both strings
1674 if expected != actual {
1675 return Fail(t, fmt.Sprintf("Error message not equal:\n"+
1676 "expected: %q\n"+
1677 "actual : %q", expected, actual), msgAndArgs...)
1678 }
1679 return true
1680}
1681
1682// ErrorContains asserts that a function returned an error (i.e. not `nil`)
1683// and that the error contains the specified substring.

Callers 10

EqualErrorFunction · 0.92
EqualErrorfFunction · 0.70
TestEqualErrorFunction · 0.70
EqualErrorMethod · 0.70

Calls 4

ErrorFunction · 0.70
FailFunction · 0.70
HelperMethod · 0.65
ErrorMethod · 0.45