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

Function _TestFileServerCleans

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

Source from the content-addressed store, hash-verified

197}
198
199func _TestFileServerCleans(t *testing.T) {
200 defer afterTest(t)
201 ch := make(chan string, 1)
202 fs := &FileServer{
203 "version",
204 &testFileSystem{
205 func(name string) (http.File, error) {
206 ch <- name
207 return nil, errors.New("file does not exist")
208 },
209 },
210 inject.CopyInject{},
211 ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
212 []routespec.RouteSpec{},
213 "",
214 }
215 tests := []struct {
216 reqPath, openArg string
217 }{
218 {"/foo.txt", "/foo.txt"},
219 {"/../foo.txt", "/foo.txt"},
220 }
221 req, _ := http.NewRequest("GET", "http://example.com", nil)
222 for n, test := range tests {
223 rec := httptest.NewRecorder()
224 req.URL.Path = test.reqPath
225 fs.ServeHTTP(rec, req)
226 if got := <-ch; got != test.openArg {
227 t.Errorf("test %d: got %q, want %q", n, got, test.openArg)
228 }
229 }
230}
231
232func mustRemoveAll(dir string) {
233 err := os.RemoveAll(dir)

Callers

nothing calls this directly

Calls 2

ServeHTTPMethod · 0.95
afterTestFunction · 0.85

Tested by

no test coverage detected