| 1562 | } |
| 1563 | |
| 1564 | func TestNoError(t *testing.T) { |
| 1565 | |
| 1566 | mockT := new(testing.T) |
| 1567 | |
| 1568 | // start with a nil error |
| 1569 | var err error |
| 1570 | |
| 1571 | True(t, NoError(mockT, err), "NoError should return True for nil arg") |
| 1572 | |
| 1573 | // now set an error |
| 1574 | err = errors.New("some error") |
| 1575 | |
| 1576 | False(t, NoError(mockT, err), "NoError with error should return False") |
| 1577 | |
| 1578 | // returning an empty error interface |
| 1579 | err = func() error { |
| 1580 | var err *customError |
| 1581 | return err |
| 1582 | }() |
| 1583 | |
| 1584 | if err == nil { // err is not nil here! |
| 1585 | t.Errorf("Error should be nil due to empty interface: %s", err) |
| 1586 | } |
| 1587 | |
| 1588 | False(t, NoError(mockT, err), "NoError should fail with empty error interface") |
| 1589 | } |
| 1590 | |
| 1591 | type customError struct{} |
| 1592 | |