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

Function TestDirJoin

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

Source from the content-addressed store, hash-verified

278}
279
280func TestDirJoin(t *testing.T) {
281 if runtime.GOOS == "windows" {
282 t.Skip("skipping test on windows")
283 }
284 wfi, err := os.Stat("/etc/hosts")
285 if err != nil {
286 t.Skip("skipping test; no /etc/hosts file")
287 }
288 test := func(d http.Dir, name string) {
289 f, err := d.Open(name)
290 if err != nil {
291 t.Fatalf("open of %s: %v", name, err)
292 }
293 defer func() { _ = f.Close() }()
294 gfi, err := f.Stat()
295 if err != nil {
296 t.Fatalf("stat of %s: %v", name, err)
297 }
298 if !os.SameFile(gfi, wfi) {
299 t.Errorf("%s got different file", name)
300 }
301 }
302 test(http.Dir("/etc/"), "/hosts")
303 test(http.Dir("/etc/"), "hosts")
304 test(http.Dir("/etc/"), "../../../../hosts")
305 test(http.Dir("/etc"), "/hosts")
306 test(http.Dir("/etc"), "hosts")
307 test(http.Dir("/etc"), "../../../../hosts")
308
309 // Not really directories, but since we use this trick in
310 // ServeFile, test it:
311 test(http.Dir("/etc/hosts"), "")
312 test(http.Dir("/etc/hosts"), "/")
313 test(http.Dir("/etc/hosts"), "../")
314}
315
316func TestEmptyDirOpenCWD(t *testing.T) {
317 test := func(d http.Dir) {

Callers

nothing calls this directly

Calls 3

StatMethod · 0.80
OpenMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected