mirror of
https://github.com/golang/go
synced 2024-11-23 13:30:08 -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) {
|
||||
req := &Request{
|
||||
Method: "POST",
|
||||
Header: Header{"Content-Type": {`multipart/form-data; boundary="foo123"`}},
|
||||
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
||||
}
|
||||
multipart, err := req.MultipartReader()
|
||||
if multipart == nil {
|
||||
t.Errorf("expected multipart; error: %v", err)
|
||||
tests := []struct {
|
||||
shouldError bool
|
||||
contentType string
|
||||
}{
|
||||
{false, `multipart/form-data; boundary="foo123"`},
|
||||
{false, `multipart/mixed; boundary="foo123"`},
|
||||
{true, `text/plain`},
|
||||
}
|
||||
|
||||
req = &Request{
|
||||
Method: "POST",
|
||||
Header: Header{"Content-Type": {`multipart/mixed; boundary="foo123"`}},
|
||||
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
||||
}
|
||||
multipart, err = req.MultipartReader()
|
||||
if multipart == nil {
|
||||
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")
|
||||
for i, test := range tests {
|
||||
req := &Request{
|
||||
Method: "POST",
|
||||
Header: Header{"Content-Type": {test.contentType}},
|
||||
Body: ioutil.NopCloser(new(bytes.Buffer)),
|
||||
}
|
||||
multipart, err := req.MultipartReader()
|
||||
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)
|
||||
}
|
||||
continue
|
||||
}
|
||||
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)
|
||||
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
conn, br, err := w.(Hijacker).Hijack()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
if r.Method != "PRI" || 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)
|
||||
}
|
||||
res, err := tr.RoundTrip(req)
|
||||
if err != nil {
|
||||
t.Errorf("%d. RoundTrip: %v", i, err)
|
||||
continue
|
||||
}
|
||||
var body []byte
|
||||
if test.compressed {
|
||||
var r *gzip.Reader
|
||||
|
Loading…
Reference in New Issue
Block a user