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{})
| 1685 | // actualObj, err := SomeFunction() |
| 1686 | // assert.ErrorContains(t, err, expectedErrorSubString) |
| 1687 | func 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. |
| 1704 | func matchRegexp(rx interface{}, str interface{}) bool { |