MCPcopy Index your code
hub / github.com/labstack/echo / TestStatic_CustomFS

Function TestStatic_CustomFS

middleware/static_test.go:454–545  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

452}
453
454func TestStatic_CustomFS(t *testing.T) {
455 var testCases = []struct {
456 name string
457 filesystem fs.FS
458 root string
459 whenURL string
460 expectContains string
461 expectCode int
462 }{
463 {
464 name: "ok, serve index with Echo message",
465 whenURL: "/",
466 filesystem: os.DirFS("../_fixture"),
467 expectCode: http.StatusOK,
468 expectContains: "<title>Echo</title>",
469 },
470
471 {
472 name: "ok, serve index with Echo message",
473 whenURL: "/_fixture/",
474 filesystem: os.DirFS(".."),
475 expectCode: http.StatusOK,
476 expectContains: "<title>Echo</title>",
477 },
478 {
479 name: "ok, serve file from map fs",
480 whenURL: "/file.txt",
481 filesystem: fstest.MapFS{
482 "file.txt": &fstest.MapFile{Data: []byte("file.txt is ok")},
483 },
484 expectCode: http.StatusOK,
485 expectContains: "file.txt is ok",
486 },
487 {
488 name: "nok, missing file in map fs",
489 whenURL: "/file.txt",
490 expectCode: http.StatusNotFound,
491 filesystem: fstest.MapFS{
492 "file2.txt": &fstest.MapFile{Data: []byte("file2.txt is ok")},
493 },
494 },
495 {
496 name: "nok, file is not a subpath of root",
497 whenURL: `/../../secret.txt`,
498 root: "/nested/folder",
499 filesystem: fstest.MapFS{
500 "secret.txt": &fstest.MapFile{Data: []byte("this is a secret")},
501 },
502 expectCode: http.StatusNotFound,
503 },
504 {
505 name: "nok, backslash is forbidden",
506 whenURL: `/..\..\secret.txt`,
507 expectCode: http.StatusNotFound,
508 root: "/nested/folder",
509 filesystem: fstest.MapFS{
510 "secret.txt": &fstest.MapFile{Data: []byte("this is a secret")},
511 },

Callers

nothing calls this directly

Calls 4

ToMiddlewareMethod · 0.95
ServeHTTPMethod · 0.80
UseMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…