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{})
| 1575 | // actualObj, err := SomeFunction() |
| 1576 | // assert.EqualError(t, err, expectedErrorString) |
| 1577 | func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool { |
| 1578 | if h, ok := t.(tHelper); ok { |
| 1579 | h.Helper() |
| 1580 | } |
| 1581 | if !Error(t, theError, msgAndArgs...) { |
| 1582 | return false |
| 1583 | } |
| 1584 | expected := errString |
| 1585 | actual := theError.Error() |
| 1586 | // don't need to use deep equals here, we know they are both strings |
| 1587 | if expected != actual { |
| 1588 | return Fail(t, fmt.Sprintf("Error message not equal:\n"+ |
| 1589 | "expected: %q\n"+ |
| 1590 | "actual : %q", expected, actual), msgAndArgs...) |
| 1591 | } |
| 1592 | return true |
| 1593 | } |
| 1594 | |
| 1595 | // ErrorContains asserts that a function returned an error (i.e. not `nil`) |
| 1596 | // and that the error contains the specified substring. |
searching dependent graphs…