MCPcopy
hub / github.com/pocketbase/pocketbase / TestFileSystemGetReader

Function TestFileSystemGetReader

tools/filesystem/filesystem_test.go:574–624  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

572}
573
574func TestFileSystemGetReader(t *testing.T) {
575 dir := createTestDir(t)
576 defer os.RemoveAll(dir)
577
578 fsys, err := filesystem.NewLocal(dir)
579 if err != nil {
580 t.Fatal(err)
581 }
582 defer fsys.Close()
583
584 scenarios := []struct {
585 file string
586 expectError bool
587 expectedContent string
588 }{
589 {"test/missing.txt", true, ""},
590 {"test/sub1.txt", false, "sub1"},
591 }
592
593 for _, s := range scenarios {
594 t.Run(s.file, func(t *testing.T) {
595 f, err := fsys.GetReader(s.file)
596 defer func() {
597 if f != nil {
598 f.Close()
599 }
600 }()
601
602 hasErr := err != nil
603 if hasErr != s.expectError {
604 t.Fatalf("Expected hasErr %v, got %v", s.expectError, hasErr)
605 }
606
607 if hasErr {
608 if !errors.Is(err, filesystem.ErrNotFound) {
609 t.Fatalf("Expected ErrNotFound error, got %v", err)
610 }
611 return
612 }
613
614 raw, err := io.ReadAll(f)
615 if err != nil {
616 t.Fatal(err)
617 }
618
619 if str := string(raw); str != s.expectedContent {
620 t.Fatalf("Expected content\n%s\ngot\n%s", s.expectedContent, str)
621 }
622 })
623 }
624}
625
626func TestFileSystemGetReuploadableFile(t *testing.T) {
627 dir := createTestDir(t)

Callers

nothing calls this directly

Calls 7

NewLocalFunction · 0.92
GetReaderMethod · 0.80
IsMethod · 0.80
createTestDirFunction · 0.70
CloseMethod · 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…