MCPcopy Index your code
hub / github.com/coder/coder / TestJustFilesSystem

Function TestJustFilesSystem

site/site_test.go:967–991  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

965}
966
967func TestJustFilesSystem(t *testing.T) {
968 t.Parallel()
969
970 tfs := fstest.MapFS{
971 "dir/foo.txt": &fstest.MapFile{
972 Data: []byte("hello world"),
973 },
974 "dir/bar.txt": &fstest.MapFile{
975 Data: []byte("hello world"),
976 },
977 }
978
979 mux := chi.NewRouter()
980 mux.Mount("/onlyfiles/", http.StripPrefix("/onlyfiles", http.FileServer(http.FS(site.OnlyFiles(tfs)))))
981 mux.Mount("/all/", http.StripPrefix("/all", http.FileServer(http.FS(tfs))))
982
983 // The /all/ endpoint should serve the directory listing.
984 resp := httptest.NewRecorder()
985 mux.ServeHTTP(resp, httptest.NewRequest("GET", "/all/dir/", nil))
986 require.Equal(t, http.StatusOK, resp.Code, "all serves the directory")
987
988 resp = httptest.NewRecorder()
989 mux.ServeHTTP(resp, httptest.NewRequest("GET", "/onlyfiles/dir/", nil))
990 require.Equal(t, http.StatusNotFound, resp.Code, "onlyfiles does not serve the directory")
991}

Callers

nothing calls this directly

Calls 3

OnlyFilesFunction · 0.92
ServeHTTPMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected