(t *testing.T)
| 237 | } |
| 238 | |
| 239 | func TestFileServerImplicitLeadingSlash(t *testing.T) { |
| 240 | defer afterTest(t) |
| 241 | tempDir, err := ioutil.TempDir("", "") |
| 242 | if err != nil { |
| 243 | t.Fatalf("TempDir: %v", err) |
| 244 | } |
| 245 | defer mustRemoveAll(tempDir) |
| 246 | if err := ioutil.WriteFile(filepath.Join(tempDir, "foo.txt"), []byte("Hello world"), 0644); err != nil { |
| 247 | t.Fatalf("WriteFile: %v", err) |
| 248 | } |
| 249 | fs := &FileServer{ |
| 250 | "version", |
| 251 | http.Dir(tempDir), |
| 252 | inject.CopyInject{}, |
| 253 | ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")), |
| 254 | []routespec.RouteSpec{}, |
| 255 | "", |
| 256 | } |
| 257 | |
| 258 | ts := httptest.NewServer(http.StripPrefix("/bar/", fs)) |
| 259 | defer ts.Close() |
| 260 | get := func(suffix string) string { |
| 261 | res, err := http.Get(ts.URL + suffix) |
| 262 | if err != nil { |
| 263 | t.Fatalf("Get %s: %v", suffix, err) |
| 264 | } |
| 265 | b, err := ioutil.ReadAll(res.Body) |
| 266 | if err != nil { |
| 267 | t.Fatalf("ReadAll %s: %v", suffix, err) |
| 268 | } |
| 269 | _ = res.Body.Close() |
| 270 | return string(b) |
| 271 | } |
| 272 | if s := get("/bar/"); !strings.Contains(s, ">foo.txt<") { |
| 273 | t.Logf("expected a directory listing with foo.txt, got %q", s) |
| 274 | } |
| 275 | if s := get("/bar/foo.txt"); s != "Hello world" { |
| 276 | t.Logf("expected %q, got %q", "Hello world", s) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func TestDirJoin(t *testing.T) { |
| 281 | if runtime.GOOS == "windows" { |
nothing calls this directly
no test coverage detected