| 965 | } |
| 966 | |
| 967 | func 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 | } |