aboutsummaryrefslogtreecommitdiff
path: root/src/testing/iotest/reader_test.go
diff options
context:
space:
mode:
authorEmmanuel T Odeke <emmanuel@orijtech.com>2020-08-17 12:25:49 -0700
committerEmmanuel Odeke <emm.odeke@gmail.com>2020-08-18 00:08:36 +0000
commitdb4cda2ec0955854c8ff556ac19ec5e67d48d090 (patch)
tree5fd92ea1827ca752bf31825cba4428171f5158f4 /src/testing/iotest/reader_test.go
parent77a11c05d6a6f766c75f804ea9b8796f9a9f85a3 (diff)
downloadgo-db4cda2ec0955854c8ff556ac19ec5e67d48d090.tar.xz
testing/iotest: correct ErrReader signature and remove exported error
Corrects ErrReader's signature to what was accepted in the approved proposal, and also removes an exported ErrIO which wasn't part of the proposal and is unnecessary. The new signature allows users to customize their own errors. While here, started examples, with ErrReader leading the way. Updates #38781 Change-Id: Ia7f84721f11061343cfef8b1adc2b7b69bc3f43c Reviewed-on: https://go-review.googlesource.com/c/go/+/248898 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/testing/iotest/reader_test.go')
-rw-r--r--src/testing/iotest/reader_test.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/testing/iotest/reader_test.go b/src/testing/iotest/reader_test.go
index ccba22ee29..6004e841e5 100644
--- a/src/testing/iotest/reader_test.go
+++ b/src/testing/iotest/reader_test.go
@@ -6,6 +6,7 @@ package iotest
import (
"bytes"
+ "errors"
"io"
"testing"
)
@@ -226,11 +227,25 @@ func TestDataErrReader_emptyReader(t *testing.T) {
}
func TestErrReader(t *testing.T) {
- n, err := ErrReader().Read([]byte{})
- if err != ErrIO {
- t.Errorf("ErrReader.Read(any) should have returned ErrIO, returned %v", err)
+ cases := []struct {
+ name string
+ err error
+ }{
+ {"nil error", nil},
+ {"non-nil error", errors.New("io failure")},
+ {"io.EOF", io.EOF},
}
- if n != 0 {
- t.Errorf("ErrReader.Read(any) should have read 0 bytes, read %v", n)
+
+ for _, tt := range cases {
+ tt := tt
+ t.Run(tt.name, func(t *testing.T) {
+ n, err := ErrReader(tt.err).Read(nil)
+ if err != tt.err {
+ t.Fatalf("Error mismatch\nGot: %v\nWant: %v", err, tt.err)
+ }
+ if n != 0 {
+ t.Fatalf("Byte count mismatch: got %d want 0", n)
+ }
+ })
}
}