mirror of https://github.com/stretchr/testify.git
add wrapper around the `EqualError` function
* add a `*Assertions` wrapper around the `EqualError` function * add testspull/60/head
parent
5c22de4a18
commit
8515a19013
|
@ -191,3 +191,16 @@ func (a *Assertions) NoError(theError error, msgAndArgs ...interface{}) bool {
|
||||||
func (a *Assertions) Error(theError error, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Error(theError error, msgAndArgs ...interface{}) bool {
|
||||||
return Error(a.t, theError, msgAndArgs...)
|
return Error(a.t, theError, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EqualError asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that it is equal to the provided error.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// if assert.Error(err, "An error was expected") {
|
||||||
|
// assert.Equal(err, expectedError)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool {
|
||||||
|
return EqualError(a.t, theError, errString, msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
|
@ -267,6 +267,23 @@ func TestErrorWrapper(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEqualErrorWrapper(t *testing.T) {
|
||||||
|
assert := New(t)
|
||||||
|
mockAssert := New(new(testing.T))
|
||||||
|
|
||||||
|
// start with a nil error
|
||||||
|
var err error
|
||||||
|
assert.False(mockAssert.EqualError(err, ""),
|
||||||
|
"EqualError should return false for nil arg")
|
||||||
|
|
||||||
|
// now set an error
|
||||||
|
err = errors.New("some error")
|
||||||
|
assert.False(mockAssert.EqualError(err, "Not some error"),
|
||||||
|
"EqualError should return false for different error string")
|
||||||
|
assert.True(mockAssert.EqualError(err, "some error"),
|
||||||
|
"EqualError should return true")
|
||||||
|
}
|
||||||
|
|
||||||
func TestEmptyWrapper(t *testing.T) {
|
func TestEmptyWrapper(t *testing.T) {
|
||||||
assert := New(t)
|
assert := New(t)
|
||||||
mockAssert := New(new(testing.T))
|
mockAssert := New(new(testing.T))
|
||||||
|
|
Loading…
Reference in New Issue