Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: add missing error checks in tests #30017

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 23 additions & 22 deletions src/net/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,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)
}

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)
tests := []struct {
shouldError bool
contentType string
}{
{false, `multipart/form-data; boundary="foo123"`},
{false, `multipart/mixed; boundary="foo123"`},
{true, `text/plain`},
}

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)
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/net/http/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4697,6 +4697,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)
Expand Down
4 changes: 4 additions & 0 deletions src/net/http/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down