| 1593 | func (*customError) Error() string { return "fail" } |
| 1594 | |
| 1595 | func TestError(t *testing.T) { |
| 1596 | |
| 1597 | mockT := new(testing.T) |
| 1598 | |
| 1599 | // start with a nil error |
| 1600 | var err error |
| 1601 | |
| 1602 | False(t, Error(mockT, err), "Error should return False for nil arg") |
| 1603 | |
| 1604 | // now set an error |
| 1605 | err = errors.New("some error") |
| 1606 | |
| 1607 | True(t, Error(mockT, err), "Error with error should return True") |
| 1608 | |
| 1609 | // go vet check |
| 1610 | True(t, Errorf(mockT, err, "example with %s", "formatted message"), "Errorf with error should return True") |
| 1611 | |
| 1612 | // returning an empty error interface |
| 1613 | err = func() error { |
| 1614 | var err *customError |
| 1615 | return err |
| 1616 | }() |
| 1617 | |
| 1618 | if err == nil { // err is not nil here! |
| 1619 | t.Errorf("Error should be nil due to empty interface: %s", err) |
| 1620 | } |
| 1621 | |
| 1622 | True(t, Error(mockT, err), "Error should pass with empty error interface") |
| 1623 | } |
| 1624 | |
| 1625 | func TestEqualError(t *testing.T) { |
| 1626 | mockT := new(testing.T) |