mirror of
https://github.com/golang/go
synced 2024-11-23 18:00: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) {
|
||||||
|
tests := []struct {
|
||||||
|
shouldError bool
|
||||||
|
contentType string
|
||||||
|
}{
|
||||||
|
{false, `multipart/form-data; boundary="foo123"`},
|
||||||
|
{false, `multipart/mixed; boundary="foo123"`},
|
||||||
|
{true, `text/plain`},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
req := &Request{
|
req := &Request{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
Header: Header{"Content-Type": {`multipart/form-data; boundary="foo123"`}},
|
Header: Header{"Content-Type": {test.contentType}},
|
||||||
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
||||||
}
|
}
|
||||||
multipart, err := req.MultipartReader()
|
multipart, err := req.MultipartReader()
|
||||||
if multipart == nil {
|
if test.shouldError {
|
||||||
t.Errorf("expected multipart; error: %v", err)
|
if err == nil || multipart != nil {
|
||||||
|
t.Errorf("test %d: unexpectedly got nil-error (%v) or non-nil-multipart (%v)", i, err, multipart)
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
req = &Request{
|
|
||||||
Method: "POST",
|
|
||||||
Header: Header{"Content-Type": {`multipart/mixed; boundary="foo123"`}},
|
|
||||||
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
|
||||||
}
|
}
|
||||||
multipart, err = req.MultipartReader()
|
if err != nil || multipart == nil {
|
||||||
if multipart == nil {
|
t.Errorf("test %d: unexpectedly got error (%v) or nil-multipart (%v)", i, err, multipart)
|
||||||
t.Errorf("expected multipart; error: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header = Header{"Content-Type": {"text/plain"}}
|
|
||||||
multipart, err = req.MultipartReader()
|
|
||||||
if multipart != nil {
|
|
||||||
t.Error("unexpected multipart for text/plain")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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