| 1446 | } |
| 1447 | |
| 1448 | func TestNoError(t *testing.T) { |
| 1449 | |
| 1450 | mockT := new(testing.T) |
| 1451 | |
| 1452 | // start with a nil error |
| 1453 | var err error |
| 1454 | |
| 1455 | True(t, NoError(mockT, err), "NoError should return True for nil arg") |
| 1456 | |
| 1457 | // now set an error |
| 1458 | err = errors.New("some error") |
| 1459 | |
| 1460 | False(t, NoError(mockT, err), "NoError with error should return False") |
| 1461 | |
| 1462 | // returning an empty error interface |
| 1463 | err = func() error { |
| 1464 | var err *customError |
| 1465 | return err |
| 1466 | }() |
| 1467 | |
| 1468 | if err == nil { // err is not nil here! |
| 1469 | t.Errorf("Error should be nil due to empty interface: %s", err) |
| 1470 | } |
| 1471 | |
| 1472 | False(t, NoError(mockT, err), "NoError should fail with empty error interface") |
| 1473 | } |
| 1474 | |
| 1475 | type customError struct{} |
| 1476 | |