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

Function ErrorContains

assert/assertions.go:1637–1651  ·  view source on GitHub ↗

ErrorContains asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring. actualObj, err := SomeFunction() assert.ErrorContains(t, err, expectedErrorSubString)

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

Source from the content-addressed store, hash-verified

1635// actualObj, err := SomeFunction()
1636// assert.ErrorContains(t, err, expectedErrorSubString)
1637func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) bool {
1638 if h, ok := t.(tHelper); ok {
1639 h.Helper()
1640 }
1641 if !Error(t, theError, msgAndArgs...) {
1642 return false
1643 }
1644
1645 actual := theError.Error()
1646 if !strings.Contains(actual, contains) {
1647 return Fail(t, fmt.Sprintf("Error %#v does not contain %#v", actual, contains), msgAndArgs...)
1648 }
1649
1650 return true
1651}
1652
1653// matchRegexp return true if a specified regexp matches a string.
1654func matchRegexp(rx interface{}, str interface{}) bool {

Callers 4

ErrorContainsFunction · 0.92
ErrorContainsfFunction · 0.70
TestErrorContainsFunction · 0.70
ErrorContainsMethod · 0.70

Calls 5

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

Tested by 1

TestErrorContainsFunction · 0.56