mirror of
https://github.com/golang/go
synced 2024-11-23 18:50:05 -07:00
net/http: use iotest.ErrReader on tests
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
4149493443
commit
45054235a0
@ -15,6 +15,7 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"testing/iotest"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -349,7 +350,7 @@ var reqWriteTests = []reqWriteTest{
|
||||
|
||||
Body: func() io.ReadCloser {
|
||||
err := errors.New("Custom reader error")
|
||||
errReader := &errorReader{err}
|
||||
errReader := iotest.ErrReader(err)
|
||||
return ioutil.NopCloser(io.MultiReader(strings.NewReader("x"), errReader))
|
||||
},
|
||||
|
||||
@ -369,7 +370,7 @@ var reqWriteTests = []reqWriteTest{
|
||||
|
||||
Body: func() io.ReadCloser {
|
||||
err := errors.New("Custom reader error")
|
||||
errReader := &errorReader{err}
|
||||
errReader := iotest.ErrReader(err)
|
||||
return ioutil.NopCloser(errReader)
|
||||
},
|
||||
|
||||
|
@ -41,6 +41,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"testing/iotest"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/http/httpguts"
|
||||
@ -3408,12 +3409,6 @@ func TestTransportIssue10457(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type errorReader struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (e errorReader) Read(p []byte) (int, error) { return 0, e.err }
|
||||
|
||||
type closerFunc func() error
|
||||
|
||||
func (f closerFunc) Close() error { return f() }
|
||||
@ -3610,7 +3605,7 @@ func TestTransportClosesBodyOnError(t *testing.T) {
|
||||
io.Reader
|
||||
io.Closer
|
||||
}{
|
||||
io.MultiReader(io.LimitReader(neverEnding('x'), 1<<20), errorReader{fakeErr}),
|
||||
io.MultiReader(io.LimitReader(neverEnding('x'), 1<<20), iotest.ErrReader(fakeErr)),
|
||||
closerFunc(func() error {
|
||||
select {
|
||||
case didClose <- true:
|
||||
|
Loading…
Reference in New Issue
Block a user