| 407 | } |
| 408 | |
| 409 | func TestServeIndexHtml(t *testing.T) { |
| 410 | defer afterTest(t) |
| 411 | const want = "index.html says hello" |
| 412 | |
| 413 | fs := &FileServer{ |
| 414 | "version", |
| 415 | http.Dir("."), |
| 416 | inject.CopyInject{}, |
| 417 | ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")), |
| 418 | []routespec.RouteSpec{}, |
| 419 | "", |
| 420 | } |
| 421 | ts := httptest.NewServer(fs) |
| 422 | defer ts.Close() |
| 423 | |
| 424 | for _, path := range []string{"/testdata/", "/testdata/index.html"} { |
| 425 | res, err := http.Get(ts.URL + path) |
| 426 | if err != nil { |
| 427 | t.Fatal(err) |
| 428 | } |
| 429 | b, err := ioutil.ReadAll(res.Body) |
| 430 | if err != nil { |
| 431 | t.Fatal("reading Body:", err) |
| 432 | } |
| 433 | if s := strings.TrimSpace(string(b)); s != want { |
| 434 | t.Errorf("for path %q got %q, want %q", path, s, want) |
| 435 | } |
| 436 | _ = res.Body.Close() |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | func TestFileServerZeroByte(t *testing.T) { |
| 441 | defer afterTest(t) |