(t *testing.T)
| 328 | } |
| 329 | |
| 330 | func 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, |
nothing calls this directly
no test coverage detected
searching dependent graphs…