MCPcopy
hub / github.com/pocketbase/pocketbase / TestFileSystemUploadFile

Function TestFileSystemUploadFile

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

Source from the content-addressed store, hash-verified

269}
270
271func TestFileSystemUploadFile(t *testing.T) {
272 dir := createTestDir(t)
273 defer os.RemoveAll(dir)
274
275 fsys, err := filesystem.NewLocal(dir)
276 if err != nil {
277 t.Fatal(err)
278 }
279 defer fsys.Close()
280
281 fileKey := "newdir/newkey.txt"
282
283 file, err := filesystem.NewFileFromPath(filepath.Join(dir, "image.svg"))
284 if err != nil {
285 t.Fatalf("Failed to load test file: %v", err)
286 }
287
288 file.OriginalName = "test.txt"
289
290 uploadErr := fsys.UploadFile(file, fileKey)
291 if uploadErr != nil {
292 t.Fatal(uploadErr)
293 }
294
295 if exists, _ := fsys.Exists(fileKey); !exists {
296 t.Fatalf("Expected %q to exist", fileKey)
297 }
298
299 attrs, err := fsys.Attributes(fileKey)
300 if err != nil {
301 t.Fatalf("Failed to fetch file attributes: %v", err)
302 }
303 if name, ok := attrs.Metadata["original-filename"]; !ok || name != file.OriginalName {
304 t.Fatalf("Expected original-filename to be %q, got %q", file.OriginalName, name)
305 }
306}
307
308func TestFileSystemUpload(t *testing.T) {
309 dir := createTestDir(t)

Callers

nothing calls this directly

Calls 8

NewLocalFunction · 0.92
NewFileFromPathFunction · 0.92
UploadFileMethod · 0.80
createTestDirFunction · 0.70
CloseMethod · 0.65
AttributesMethod · 0.65
RemoveAllMethod · 0.45
ExistsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…