MCPcopy
hub / github.com/cortesi/devd / TestServeIndexHtml

Function TestServeIndexHtml

fileserver/fileserver_test.go:409–438  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

407}
408
409func 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
440func TestFileServerZeroByte(t *testing.T) {
441 defer afterTest(t)

Callers

nothing calls this directly

Calls 2

afterTestFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected