diff options
Diffstat (limited to 'streamio/stream_test.go')
-rw-r--r-- | streamio/stream_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/streamio/stream_test.go b/streamio/stream_test.go index c91d5a58f..8f7c841fd 100644 --- a/streamio/stream_test.go +++ b/streamio/stream_test.go @@ -2,6 +2,7 @@ package streamio import ( "bytes" + "errors" "fmt" "io" "strings" @@ -60,6 +61,25 @@ func TestReadSizes(t *testing.T) { }) } +func TestRead_rememberError(t *testing.T) { + firstRead := true + myError := errors.New("hello world") + r := NewReader(func() ([]byte, error) { + if firstRead { + firstRead = false + return nil, myError + } + panic("should never be reached") + }) + + // Intentionally call Read more than once. We want the error to be + // sticky. + for i := 0; i < 10; i++ { + _, err := r.Read(nil) + require.Equal(t, err, myError) + } +} + func receiverFromReader(r io.Reader) func() ([]byte, error) { return func() ([]byte, error) { data := make([]byte, 10) |