github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/internal/testutil/helpers.go (about)

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