MCPcopy Create free account
hub / github.com/stretchr/testify / EqualError

Function EqualError

assert/assertions.go:1614–1630  ·  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

1612// actualObj, err := SomeFunction()
1613// assert.EqualError(t, err, expectedErrorString)
1614func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool {
1615 if h, ok := t.(tHelper); ok {
1616 h.Helper()
1617 }
1618 if !Error(t, theError, msgAndArgs...) {
1619 return false
1620 }
1621 expected := errString
1622 actual := theError.Error()
1623 // don't need to use deep equals here, we know they are both strings
1624 if expected != actual {
1625 return Fail(t, fmt.Sprintf("Error message not equal:\n"+
1626 "expected: %q\n"+
1627 "actual : %q", expected, actual), msgAndArgs...)
1628 }
1629 return true
1630}
1631
1632// ErrorContains asserts that a function returned an error (i.e. not `nil`)
1633// 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