]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: Add more call order tests for request form parsing.
authorMatthew Cottingham <mattcottingham@gmail.com>
Mon, 6 Jan 2014 18:36:04 +0000 (10:36 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 6 Jan 2014 18:36:04 +0000 (10:36 -0800)
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

src/pkg/net/http/request.go
src/pkg/net/http/request_test.go

index 6ed21af568e5e9b0d66abc1da978d96e440023a4..7a97770314d7f824f87d754d53ac8c044b13fa5c 100644 (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
 }
index 17af781c9dbfaed5874ba9229a6b07c2d7e5797a..0c1e16b8d5eb93de47f610777a55d0c4db638d5c 100644 (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)
+       }
+       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")
        }
 }