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{})
| 1612 | // actualObj, err := SomeFunction() |
| 1613 | // assert.EqualError(t, err, expectedErrorString) |
| 1614 | func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool { |
| 1615 | if h, ok := t.(tHelper); ok { |
| 1616 | h.Helper() |
| 1617 | } |
| 1618 | if !Error(t, theError, msgAndArgs...) { |
| 1619 | return false |
| 1620 | } |
| 1621 | expected := errString |
| 1622 | actual := theError.Error() |
| 1623 | // don't need to use deep equals here, we know they are both strings |
| 1624 | if expected != actual { |
| 1625 | return Fail(t, fmt.Sprintf("Error message not equal:\n"+ |
| 1626 | "expected: %q\n"+ |
| 1627 | "actual : %q", expected, actual), msgAndArgs...) |
| 1628 | } |
| 1629 | return true |
| 1630 | } |
| 1631 | |
| 1632 | // ErrorContains asserts that a function returned an error (i.e. not `nil`) |
| 1633 | // and that the error contains the specified substring. |