Commit 991e9a83 authored by Matthew Cottingham's avatar Matthew Cottingham Committed by Brad Fitzpatrick

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
parent 65767579
......@@ -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
}
......
......@@ -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)
}
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)
}
err = req.ParseMultipartForm(1024)
if err == nil {
t.Errorf("expected an error from ParseMultipartForm after call to MultipartReader")
if _, _, err := req.FormFile(""); err == nil {
t.Fatal("expected an error from FormFile after call to MultipartReader")
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment