MCPcopy
hub / github.com/pocketbase/pocketbase / TestEventFileFS

Function TestEventFileFS

tools/router/event_test.go:577–671  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

575}
576
577func TestEventFileFS(t *testing.T) {
578 // stub test files
579 // ---
580 dir, err := os.MkdirTemp("", "EventFileFS")
581 if err != nil {
582 t.Fatal(err)
583 }
584 defer os.RemoveAll(dir)
585
586 err = os.WriteFile(filepath.Join(dir, "index.html"), []byte("index"), 0644)
587 if err != nil {
588 t.Fatal(err)
589 }
590
591 err = os.WriteFile(filepath.Join(dir, "test.txt"), []byte("test"), 0644)
592 if err != nil {
593 t.Fatal(err)
594 }
595
596 // create sub directory with an index.html file inside it
597 err = os.MkdirAll(filepath.Join(dir, "sub1"), os.ModePerm)
598 if err != nil {
599 t.Fatal(err)
600 }
601 err = os.WriteFile(filepath.Join(dir, "sub1", "index.html"), []byte("sub1 index"), 0644)
602 if err != nil {
603 t.Fatal(err)
604 }
605
606 err = os.MkdirAll(filepath.Join(dir, "sub2"), os.ModePerm)
607 if err != nil {
608 t.Fatal(err)
609 }
610 err = os.WriteFile(filepath.Join(dir, "sub2", "test.txt"), []byte("sub2 test"), 0644)
611 if err != nil {
612 t.Fatal(err)
613 }
614 // ---
615
616 scenarios := []struct {
617 name string
618 path string
619 expected string
620 }{
621 {"missing file", "", ""},
622 {"root with no explicit file", "", ""},
623 {"root with explicit file", "test.txt", "test"},
624 {"sub dir with no explicit file", "sub1", "sub1 index"},
625 {"sub dir with no explicit file (no index.html)", "sub2", ""},
626 {"sub dir explicit file", "sub2/test.txt", "sub2 test"},
627 }
628
629 for _, s := range scenarios {
630 t.Run(s.name, func(t *testing.T) {
631 req, err := http.NewRequest(http.MethodGet, "/", nil)
632 if err != nil {
633 t.Fatal(err)
634 }

Callers

nothing calls this directly

Calls 5

FileFSMethod · 0.95
CloseMethod · 0.65
GetMethod · 0.65
RemoveAllMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…