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{})
| 1598 | // actualObj, err := SomeFunction() |
| 1599 | // assert.ErrorContains(t, err, expectedErrorSubString) |
| 1600 | func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) bool { |
| 1601 | if h, ok := t.(tHelper); ok { |
| 1602 | h.Helper() |
| 1603 | } |
| 1604 | if !Error(t, theError, msgAndArgs...) { |
| 1605 | return false |
| 1606 | } |
| 1607 | |
| 1608 | actual := theError.Error() |
| 1609 | if !strings.Contains(actual, contains) { |
| 1610 | return Fail(t, fmt.Sprintf("Error %#v does not contain %#v", actual, contains), msgAndArgs...) |
| 1611 | } |
| 1612 | |
| 1613 | return true |
| 1614 | } |
| 1615 | |
| 1616 | // matchRegexp return true if a specified regexp matches a string. |
| 1617 | func matchRegexp(rx interface{}, str interface{}) bool { |
searching dependent graphs…