MCPcopy
hub / github.com/pocketbase/pocketbase / TestFileSystemServe

Function TestFileSystemServe

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

Source from the content-addressed store, hash-verified

328}
329
330func TestFileSystemServe(t *testing.T) {
331 dir := createTestDir(t)
332 defer os.RemoveAll(dir)
333
334 fsys, err := filesystem.NewLocal(dir)
335 if err != nil {
336 t.Fatal(err)
337 }
338 defer fsys.Close()
339
340 csp := "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'; sandbox"
341 cacheControl := "max-age=2592000, stale-while-revalidate=86400"
342
343 scenarios := []struct {
344 path string
345 name string
346 query map[string]string
347 headers map[string]string
348 expectError bool
349 expectHeaders map[string]string
350 }{
351 {
352 // missing
353 "missing.txt",
354 "test_name.txt",
355 nil,
356 nil,
357 true,
358 nil,
359 },
360 {
361 // existing regular file
362 "test/sub1.txt",
363 "test_name.txt",
364 nil,
365 nil,
366 false,
367 map[string]string{
368 "Content-Disposition": "attachment; filename=test_name.txt",
369 "Content-Type": "application/octet-stream",
370 "Content-Length": "4",
371 "Content-Security-Policy": csp,
372 "Cache-Control": cacheControl,
373 },
374 },
375 {
376 // png inline
377 "image.png",
378 "test_name.png",
379 nil,
380 nil,
381 false,
382 map[string]string{
383 "Content-Disposition": "inline; filename=test_name.png",
384 "Content-Type": "image/png",
385 "Content-Length": "73",
386 "Content-Security-Policy": csp,
387 "Cache-Control": cacheControl,

Callers

nothing calls this directly

Calls 10

NewLocalFunction · 0.92
QueryMethod · 0.80
EncodeMethod · 0.80
ServeMethod · 0.80
createTestDirFunction · 0.70
CloseMethod · 0.65
SetMethod · 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…