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

Function ErrorContains

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

1685// actualObj, err := SomeFunction()
1686// assert.ErrorContains(t, err, expectedErrorSubString)
1687func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) bool {
1688 if h, ok := t.(tHelper); ok {
1689 h.Helper()
1690 }
1691 if !Error(t, theError, msgAndArgs...) {
1692 return false
1693 }
1694
1695 actual := theError.Error()
1696 if !strings.Contains(actual, contains) {
1697 return Fail(t, fmt.Sprintf("Error %#v does not contain %#v", actual, contains), msgAndArgs...)
1698 }
1699
1700 return true
1701}
1702
1703// matchRegexp return true if a specified regexp matches a string.
1704func 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