1
0
mirror of https://github.com/golang/go synced 2024-09-25 07:20:12 -06:00

net/http: Add more call order tests for request form parsing.

Adds tests for branches handling call ordering which
were shown to be untested by the cover tool.

This is part of the refactoring of form parsing discussed
in CL 44040043. These tests may need to be changed later but
should help lock in the current behaviour.

R=golang-codereviews, dave, bradfitz
CC=golang-codereviews
https://golang.org/cl/46750043
This commit is contained in:
Matthew Cottingham 2014-01-06 10:36:04 -08:00 committed by Brad Fitzpatrick
parent 6576757927
commit 991e9a8331
2 changed files with 31 additions and 7 deletions

View File

@ -708,7 +708,7 @@ func parsePostForm(r *Request) (vs url.Values, err error) {
// orders to call too many functions here.
// Clean this up and write more tests.
// request_test.go contains the start of this,
// in TestRequestMultipartCallOrder.
// in TestParseMultipartFormOrder and others.
}
return
}

View File

@ -199,15 +199,39 @@ func TestEmptyMultipartRequest(t *testing.T) {
testMissingFile(t, req)
}
func TestRequestMultipartCallOrder(t *testing.T) {
// Test that ParseMultipartForm errors if called
// after MultipartReader on the same request.
func TestParseMultipartFormOrder(t *testing.T) {
req := newTestMultipartRequest(t)
_, err := req.MultipartReader()
if err != nil {
if _, err := req.MultipartReader(); err != nil {
t.Fatalf("MultipartReader: %v", err)
}
err = req.ParseMultipartForm(1024)
if err == nil {
t.Errorf("expected an error from ParseMultipartForm after call to MultipartReader")
if err := req.ParseMultipartForm(1024); err == nil {
t.Fatal("expected an error from ParseMultipartForm after call to MultipartReader")
}
}
// Test that MultipartReader errors if called
// after ParseMultipartForm on the same request.
func TestMultipartReaderOrder(t *testing.T) {
req := newTestMultipartRequest(t)
if err := req.ParseMultipartForm(25); err != nil {
t.Fatalf("ParseMultipartForm: %v", err)
}
if _, err := req.MultipartReader(); err == nil {
t.Fatal("expected an error from MultipartReader after call to ParseMultipartForm")
}
}
// Test that FormFile errors if called after
// MultipartReader on the same request.
func TestFormFileOrder(t *testing.T) {
req := newTestMultipartRequest(t)
if _, err := req.MultipartReader(); err != nil {
t.Fatalf("MultipartReader: %v", err)
}
if _, _, err := req.FormFile(""); err == nil {
t.Fatal("expected an error from FormFile after call to MultipartReader")
}
}