mirror of
https://github.com/golang/go
synced 2024-11-23 15:40:06 -07:00
net/http: add missing error checks in tests
Change-Id: I73441ba2eb349f0e0f25068e6b24c74dd33f1456
GitHub-Last-Rev: b9e6705962
GitHub-Pull-Request: golang/go#30017
Reviewed-on: https://go-review.googlesource.com/c/go/+/160441
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c9ccdf1f8c
commit
62bfa69e6e
@ -135,30 +135,31 @@ func TestParseFormInitializeOnError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultipartReader(t *testing.T) {
|
func TestMultipartReader(t *testing.T) {
|
||||||
req := &Request{
|
tests := []struct {
|
||||||
Method: "POST",
|
shouldError bool
|
||||||
Header: Header{"Content-Type": {`multipart/form-data; boundary="foo123"`}},
|
contentType string
|
||||||
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
}{
|
||||||
}
|
{false, `multipart/form-data; boundary="foo123"`},
|
||||||
multipart, err := req.MultipartReader()
|
{false, `multipart/mixed; boundary="foo123"`},
|
||||||
if multipart == nil {
|
{true, `text/plain`},
|
||||||
t.Errorf("expected multipart; error: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req = &Request{
|
for i, test := range tests {
|
||||||
Method: "POST",
|
req := &Request{
|
||||||
Header: Header{"Content-Type": {`multipart/mixed; boundary="foo123"`}},
|
Method: "POST",
|
||||||
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
Header: Header{"Content-Type": {test.contentType}},
|
||||||
}
|
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
||||||
multipart, err = req.MultipartReader()
|
}
|
||||||
if multipart == nil {
|
multipart, err := req.MultipartReader()
|
||||||
t.Errorf("expected multipart; error: %v", err)
|
if test.shouldError {
|
||||||
}
|
if err == nil || multipart != nil {
|
||||||
|
t.Errorf("test %d: unexpectedly got nil-error (%v) or non-nil-multipart (%v)", i, err, multipart)
|
||||||
req.Header = Header{"Content-Type": {"text/plain"}}
|
}
|
||||||
multipart, err = req.MultipartReader()
|
continue
|
||||||
if multipart != nil {
|
}
|
||||||
t.Error("unexpected multipart for text/plain")
|
if err != nil || multipart == nil {
|
||||||
|
t.Errorf("test %d: unexpectedly got error (%v) or nil-multipart (%v)", i, err, multipart)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4706,6 +4706,10 @@ func TestServerHandlersCanHandleH2PRI(t *testing.T) {
|
|||||||
defer afterTest(t)
|
defer afterTest(t)
|
||||||
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||||
conn, br, err := w.(Hijacker).Hijack()
|
conn, br, err := w.(Hijacker).Hijack()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
if r.Method != "PRI" || r.RequestURI != "*" {
|
if r.Method != "PRI" || r.RequestURI != "*" {
|
||||||
t.Errorf("Got method/target %q %q; want PRI *", r.Method, r.RequestURI)
|
t.Errorf("Got method/target %q %q; want PRI *", r.Method, r.RequestURI)
|
||||||
|
@ -865,6 +865,10 @@ func TestRoundTripGzip(t *testing.T) {
|
|||||||
req.Header.Set("Accept-Encoding", test.accept)
|
req.Header.Set("Accept-Encoding", test.accept)
|
||||||
}
|
}
|
||||||
res, err := tr.RoundTrip(req)
|
res, err := tr.RoundTrip(req)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%d. RoundTrip: %v", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
var body []byte
|
var body []byte
|
||||||
if test.compressed {
|
if test.compressed {
|
||||||
var r *gzip.Reader
|
var r *gzip.Reader
|
||||||
|
Loading…
Reference in New Issue
Block a user