MCPcopy
hub / github.com/pocketbase/pocketbase / TestFileSystemCreateThumb

Function TestFileSystemCreateThumb

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

Source from the content-addressed store, hash-verified

873}
874
875func TestFileSystemCreateThumb(t *testing.T) {
876 dir := createTestDir(t)
877 defer os.RemoveAll(dir)
878
879 fsys, err := filesystem.NewLocal(dir)
880 if err != nil {
881 t.Fatal(err)
882 }
883 defer fsys.Close()
884
885 scenarios := []struct {
886 file string
887 thumb string
888 size string
889 expectedMimeType string
890 }{
891 // missing
892 {"missing.txt", "thumb_test_missing", "100x100", ""},
893 // non-image existing file
894 {"test/sub1.txt", "thumb_test_sub1", "100x100", ""},
895 // existing image file with existing thumb path = should fail
896 {"image.png", "test", "100x100", ""},
897 // existing image file with invalid thumb size
898 {"image.png", "thumb0", "invalid", ""},
899 // existing image file with 0xH thumb size
900 {"image.png", "thumb_0xH", "0x100", "image/png"},
901 // existing image file with Wx0 thumb size
902 {"image.png", "thumb_Wx0", "100x0", "image/png"},
903 // existing image file with WxH thumb size
904 {"image.png", "thumb_WxH", "100x100", "image/png"},
905 // existing image file with WxHt thumb size
906 {"image.png", "thumb_WxHt", "100x100t", "image/png"},
907 // existing image file with WxHb thumb size
908 {"image.png", "thumb_WxHb", "100x100b", "image/png"},
909 // existing image file with WxHf thumb size
910 {"image.png", "thumb_WxHf", "100x100f", "image/png"},
911 // jpg
912 {"image.jpg", "thumb.jpg", "100x100", "image/jpeg"},
913 // webp (should produce png)
914 {"image.webp", "thumb.webp", "100x100", "image/png"},
915 // without extension (should extract the mimetype from its stored ContentType)
916 {"image_noext", "image_noext.jpeg", "100x100", "image/jpeg"},
917 }
918
919 for _, s := range scenarios {
920 t.Run(s.file+"_"+s.thumb+"_"+s.size, func(t *testing.T) {
921 err := fsys.CreateThumb(s.file, s.thumb, s.size)
922
923 expectErr := s.expectedMimeType == ""
924
925 hasErr := err != nil
926 if hasErr != expectErr {
927 t.Fatalf("Expected hasErr to be %v, got %v (%v)", expectErr, hasErr, err)
928 }
929
930 if hasErr {
931 return
932 }

Callers

nothing calls this directly

Calls 9

NewLocalFunction · 0.92
CreateThumbMethod · 0.80
GetReaderMethod · 0.80
ContentTypeMethod · 0.80
createTestDirFunction · 0.70
CloseMethod · 0.65
RemoveAllMethod · 0.45
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…