mirror of
https://github.com/golang/go
synced 2024-11-23 21:20:03 -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"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"testing/iotest"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -349,7 +350,7 @@ var reqWriteTests = []reqWriteTest{
|
|||||||
|
|
||||||
Body: func() io.ReadCloser {
|
Body: func() io.ReadCloser {
|
||||||
err := errors.New("Custom reader error")
|
err := errors.New("Custom reader error")
|
||||||
errReader := &errorReader{err}
|
errReader := iotest.ErrReader(err)
|
||||||
return ioutil.NopCloser(io.MultiReader(strings.NewReader("x"), errReader))
|
return ioutil.NopCloser(io.MultiReader(strings.NewReader("x"), errReader))
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -369,7 +370,7 @@ var reqWriteTests = []reqWriteTest{
|
|||||||
|
|
||||||
Body: func() io.ReadCloser {
|
Body: func() io.ReadCloser {
|
||||||
err := errors.New("Custom reader error")
|
err := errors.New("Custom reader error")
|
||||||
errReader := &errorReader{err}
|
errReader := iotest.ErrReader(err)
|
||||||
return ioutil.NopCloser(errReader)
|
return ioutil.NopCloser(errReader)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
"testing/iotest"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/http/httpguts"
|
"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
|
type closerFunc func() error
|
||||||
|
|
||||||
func (f closerFunc) Close() error { return f() }
|
func (f closerFunc) Close() error { return f() }
|
||||||
@ -3610,7 +3605,7 @@ func TestTransportClosesBodyOnError(t *testing.T) {
|
|||||||
io.Reader
|
io.Reader
|
||||||
io.Closer
|
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 {
|
closerFunc(func() error {
|
||||||
select {
|
select {
|
||||||
case didClose <- true:
|
case didClose <- true:
|
||||||
|
Loading…
Reference in New Issue
Block a user