1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:50:07 -07:00

net/http: add missing error checks in tests

This commit is contained in:
Leon Klingele 2019-01-30 18:13:42 +01:00
parent 56c9f8e8cf
commit b9e6705962
No known key found for this signature in database
GPG Key ID: 0C8AF48831EEC211
3 changed files with 31 additions and 22 deletions

View File

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

View File

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

View File

@ -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