1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:57:57 -07:00

http: add test to serve content in index.html

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4798071
This commit is contained in:
Yasuhiro Matsumoto 2011-08-09 10:25:53 -07:00 committed by Brad Fitzpatrick
parent 1adda4601a
commit 29df7bb7ec
2 changed files with 22 additions and 0 deletions

View 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 {

1
src/pkg/http/testdata/index.html vendored Normal file
View File

@ -0,0 +1 @@
index.html says hello