| 1477 | func (*customError) Error() string { return "fail" } |
| 1478 | |
| 1479 | func TestError(t *testing.T) { |
| 1480 | |
| 1481 | mockT := new(testing.T) |
| 1482 | |
| 1483 | // start with a nil error |
| 1484 | var err error |
| 1485 | |
| 1486 | False(t, Error(mockT, err), "Error should return False for nil arg") |
| 1487 | |
| 1488 | // now set an error |
| 1489 | err = errors.New("some error") |
| 1490 | |
| 1491 | True(t, Error(mockT, err), "Error with error should return True") |
| 1492 | |
| 1493 | // go vet check |
| 1494 | True(t, Errorf(mockT, err, "example with %s", "formatted message"), "Errorf with error should return True") |
| 1495 | |
| 1496 | // returning an empty error interface |
| 1497 | err = func() error { |
| 1498 | var err *customError |
| 1499 | return err |
| 1500 | }() |
| 1501 | |
| 1502 | if err == nil { // err is not nil here! |
| 1503 | t.Errorf("Error should be nil due to empty interface: %s", err) |
| 1504 | } |
| 1505 | |
| 1506 | True(t, Error(mockT, err), "Error should pass with empty error interface") |
| 1507 | } |
| 1508 | |
| 1509 | func TestEqualError(t *testing.T) { |
| 1510 | mockT := new(testing.T) |