diff options
author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2011-08-09 10:25:53 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2011-08-09 10:25:53 -0700 |
commit | 29df7bb7ecf311f3c863754fb8215396923a0261 (patch) | |
tree | 3f0a2e2fe0a5c1db66f589c83875a8583b568bb8 | |
parent | 1adda4601aa9c28199f265d5826fd9c31ee73f64 (diff) | |
download | go-29df7bb7ecf311f3c863754fb8215396923a0261.tar.gz go-29df7bb7ecf311f3c863754fb8215396923a0261.zip |
http: add test to serve content in index.html
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4798071
-rw-r--r-- | src/pkg/http/fs_test.go | 21 | ||||
-rw-r--r-- | src/pkg/http/testdata/index.html | 1 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/pkg/http/fs_test.go b/src/pkg/http/fs_test.go index 14f1645c3c..823770ec4f 100644 --- a/src/pkg/http/fs_test.go +++ b/src/pkg/http/fs_test.go @@ -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 index 0000000000..da8e1e93d1 --- /dev/null +++ b/src/pkg/http/testdata/index.html @@ -0,0 +1 @@ +index.html says hello |