]> Cypherpunks repositories - gostls13.git/commitdiff
http: add test to serve content in index.html
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Tue, 9 Aug 2011 17:25:53 +0000 (10:25 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 9 Aug 2011 17:25:53 +0000 (10:25 -0700)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4798071

src/pkg/http/fs_test.go
src/pkg/http/testdata/index.html [new file with mode: 0644]

index 14f1645c3c0f169f0932c52bc4b21eb1d627178a..823770ec4f38795bc2019f24dc612cdaa8d6c4e0 100644 (file)
@@ -261,6 +261,27 @@ func TestServeFileWithContentEncoding(t *testing.T) {
        }
 }
 
+func TestServeIndexHtml(t *testing.T) {
+       const want = "index.html says hello\n"
+       ts := httptest.NewServer(FileServer(Dir(".")))
+       defer ts.Close()
+
+       for _, path := range []string{"/testdata/", "/testdata/index.html"} {
+               res, err := Get(ts.URL + path)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               defer res.Body.Close()
+               b, err := ioutil.ReadAll(res.Body)
+               if err != nil {
+                       t.Fatal("reading Body:", err)
+               }
+               if s := string(b); s != want {
+                       t.Errorf("for path %q got %q, want %q", path, s, want)
+               }
+       }
+}
+
 func getBody(t *testing.T, req Request) (*Response, []byte) {
        r, err := DefaultClient.Do(&req)
        if err != nil {
diff --git a/src/pkg/http/testdata/index.html b/src/pkg/http/testdata/index.html
new file mode 100644 (file)
index 0000000..da8e1e9
--- /dev/null
@@ -0,0 +1 @@
+index.html says hello