]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: clean up fs tests a bit
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 3 Jul 2012 17:17:55 +0000 (10:17 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 3 Jul 2012 17:17:55 +0000 (10:17 -0700)
And fix some govet-caught format arg issues.

R=r
CC=golang-dev
https://golang.org/cl/6354068

src/pkg/net/http/fs_test.go
src/pkg/net/http/serve_test.go

index 12b51aea72ea836699ff402362615435412101bd..35c6ba617e24a932ff7837c8d521815c9c4cc082 100644 (file)
@@ -81,6 +81,7 @@ func TestServeFile(t *testing.T) {
        }
 
        // Range tests
+Cases:
        for _, rt := range ServeFileRangeTests {
                if rt.r != "" {
                        req.Header.Set("Range", rt.r)
@@ -109,7 +110,7 @@ func TestServeFile(t *testing.T) {
                                t.Errorf("range=%q: body = %q, want %q", rt.r, body, wantBody)
                        }
                        if strings.HasPrefix(ct, "multipart/byteranges") {
-                               t.Errorf("range=%q content-type = %q; unexpected multipart/byteranges", rt.r)
+                               t.Errorf("range=%q content-type = %q; unexpected multipart/byteranges", rt.r, ct)
                        }
                }
                if len(rt.ranges) > 1 {
@@ -119,37 +120,41 @@ func TestServeFile(t *testing.T) {
                                continue
                        }
                        if typ != "multipart/byteranges" {
-                               t.Errorf("range=%q content-type = %q; want multipart/byteranges", rt.r)
+                               t.Errorf("range=%q content-type = %q; want multipart/byteranges", rt.r, typ)
                                continue
                        }
                        if params["boundary"] == "" {
                                t.Errorf("range=%q content-type = %q; lacks boundary", rt.r, ct)
+                               continue
                        }
                        if g, w := resp.ContentLength, int64(len(body)); g != w {
                                t.Errorf("range=%q Content-Length = %d; want %d", rt.r, g, w)
+                               continue
                        }
                        mr := multipart.NewReader(bytes.NewReader(body), params["boundary"])
                        for ri, rng := range rt.ranges {
                                part, err := mr.NextPart()
                                if err != nil {
-                                       t.Fatalf("range=%q, reading part index %d: %v", rt.r, ri, err)
+                                       t.Errorf("range=%q, reading part index %d: %v", rt.r, ri, err)
+                                       continue Cases
+                               }
+                               wantContentRange = fmt.Sprintf("bytes %d-%d/%d", rng.start, rng.end-1, testFileLen)
+                               if g, w := part.Header.Get("Content-Range"), wantContentRange; g != w {
+                                       t.Errorf("range=%q: part Content-Range = %q; want %q", rt.r, g, w)
                                }
                                body, err := ioutil.ReadAll(part)
                                if err != nil {
-                                       t.Fatalf("range=%q, reading part index %d body: %v", rt.r, ri, err)
+                                       t.Errorf("range=%q, reading part index %d body: %v", rt.r, ri, err)
+                                       continue Cases
                                }
-                               wantContentRange = fmt.Sprintf("bytes %d-%d/%d", rng.start, rng.end-1, testFileLen)
                                wantBody := file[rng.start:rng.end]
                                if !bytes.Equal(body, wantBody) {
                                        t.Errorf("range=%q: body = %q, want %q", rt.r, body, wantBody)
                                }
-                               if g, w := part.Header.Get("Content-Range"), wantContentRange; g != w {
-                                       t.Errorf("range=%q: part Content-Range = %q; want %q", rt.r, g, w)
-                               }
                        }
                        _, err = mr.NextPart()
                        if err != io.EOF {
-                               t.Errorf("range=%q; expected final error io.EOF; got %v", err)
+                               t.Errorf("range=%q; expected final error io.EOF; got %v", rt.r, err)
                        }
                }
        }
index b6e8b6cf73d6d9c55f68a6192503a686965e8357..77ab2eb334998c770c3618b2d6c418095d0b821d 100644 (file)
@@ -1283,15 +1283,15 @@ func BenchmarkServer(b *testing.B) {
                for i := 0; i < n; i++ {
                        res, err := Get(url)
                        if err != nil {
-                               log.Panicf("Get:", err)
+                               log.Panicf("Get: %v", err)
                        }
                        all, err := ioutil.ReadAll(res.Body)
                        if err != nil {
-                               log.Panicf("ReadAll:", err)
+                               log.Panicf("ReadAll: %v", err)
                        }
                        body := string(all)
                        if body != "Hello world.\n" {
-                               log.Panicf("Got body:", body)
+                               log.Panicf("Got body: %q", body)
                        }
                }
                os.Exit(0)