helpers.go 642 B

123456789101112131415161718192021222324252627
  1. package testutil
  2. import (
  3. "io"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. )
  7. // ErrorContains checks that the error is not nil, and contains the expected
  8. // substring.
  9. func ErrorContains(t require.TestingT, err error, expectedError string, msgAndArgs ...interface{}) {
  10. require.Error(t, err, msgAndArgs...)
  11. assert.Contains(t, err.Error(), expectedError, msgAndArgs...)
  12. }
  13. // DevZero acts like /dev/zero but in an OS-independent fashion.
  14. var DevZero io.Reader = devZero{}
  15. type devZero struct{}
  16. func (d devZero) Read(p []byte) (n int, err error) {
  17. for i := range p {
  18. p[i] = 0
  19. }
  20. return len(p), nil
  21. }