| 197 | } |
| 198 | |
| 199 | func _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 | |
| 232 | func mustRemoveAll(dir string) { |
| 233 | err := os.RemoveAll(dir) |