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{})
| 1662 | // actualObj, err := SomeFunction() |
| 1663 | // assert.EqualError(t, err, expectedErrorString) |
| 1664 | func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool { |
| 1665 | if h, ok := t.(tHelper); ok { |
| 1666 | h.Helper() |
| 1667 | } |
| 1668 | if !Error(t, theError, msgAndArgs...) { |
| 1669 | return false |
| 1670 | } |
| 1671 | expected := errString |
| 1672 | actual := theError.Error() |
| 1673 | // don't need to use deep equals here, we know they are both strings |
| 1674 | if expected != actual { |
| 1675 | return Fail(t, fmt.Sprintf("Error message not equal:\n"+ |
| 1676 | "expected: %q\n"+ |
| 1677 | "actual : %q", expected, actual), msgAndArgs...) |
| 1678 | } |
| 1679 | return true |
| 1680 | } |
| 1681 | |
| 1682 | // ErrorContains asserts that a function returned an error (i.e. not `nil`) |
| 1683 | // and that the error contains the specified substring. |