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

Function TestNotFoundOverride

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

Source from the content-addressed store, hash-verified

514}
515
516func TestNotFoundOverride(t *testing.T) {
517 defer afterTest(t)
518 ffile := &fakeFileInfo{
519 basename: "foo.html",
520 modtime: time.Unix(1000000000, 0).UTC(),
521 contents: "I am a fake file",
522 }
523 fsys := fakeFS{
524 "/": &fakeFileInfo{
525 dir: true,
526 modtime: time.Unix(123, 0).UTC(),
527 ents: []*fakeFileInfo{},
528 },
529 "/one": &fakeFileInfo{
530 dir: true,
531 modtime: time.Unix(123, 0).UTC(),
532 ents: []*fakeFileInfo{ffile},
533 },
534 "/one/foo.html": ffile,
535 }
536
537 fs := &FileServer{
538 "version",
539 fsys,
540 inject.CopyInject{},
541 ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
542 []routespec.RouteSpec{
543 {Host: "", Path: "/", Value: "foo.html"},
544 },
545 "",
546 }
547
548 ts := httptest.NewServer(fs)
549 defer ts.Close()
550
551 res, err := http.Get(ts.URL + "/one/nonexistent.html")
552 if err != nil {
553 t.Fatal(err)
554 }
555 _ = res.Body.Close()
556 if res.StatusCode != 200 {
557 t.Error("Expected to find over-ride file.")
558 }
559
560 res, err = http.Get(ts.URL + "/one/two/nonexistent.html")
561 if err != nil {
562 t.Fatal(err)
563 }
564 _ = res.Body.Close()
565 if res.StatusCode != 200 {
566 t.Error("Expected to find over-ride file.")
567 }
568
569 res, err = http.Get(ts.URL + "/nonexistent.html")
570 if err != nil {
571 t.Fatal(err)
572 }
573 _ = res.Body.Close()

Callers

nothing calls this directly

Calls 2

afterTestFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected