diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-07 00:41:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-07 00:41:45 +0300 |
| commit | e98f0edb56f3d2355adf83a79edcc8ec2fa65a18 (patch) | |
| tree | 64c958a8d81633bbd92aaf39932ace60beeeca6a /internal/api/handlers_more_test.go | |
| parent | 2985cbc5d84d6841bed8a249308eeaeb70bb3c83 (diff) | |
Fix static file read seeker guard for s0
Diffstat (limited to 'internal/api/handlers_more_test.go')
| -rw-r--r-- | internal/api/handlers_more_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/api/handlers_more_test.go b/internal/api/handlers_more_test.go index 6a4353e..0403f25 100644 --- a/internal/api/handlers_more_test.go +++ b/internal/api/handlers_more_test.go @@ -196,6 +196,36 @@ func TestServer_ServeFile_notFound(t *testing.T) { } } +type statErrorFS struct{} + +func (statErrorFS) Open(string) (http.File, error) { + return statErrorFile{}, nil +} + +type statErrorFile struct{} + +func (statErrorFile) Close() error { return nil } + +func (statErrorFile) Read([]byte) (int, error) { return 0, io.EOF } + +func (statErrorFile) Seek(int64, int) (int64, error) { return 0, nil } + +func (statErrorFile) Readdir(int) ([]os.FileInfo, error) { return nil, nil } + +func (statErrorFile) Stat() (os.FileInfo, error) { return nil, errors.New("stat failed") } + +func TestServer_ServeFile_statError(t *testing.T) { + srv := &Server{staticFS: statErrorFS{}} + req := httptest.NewRequest(http.MethodGet, "/", nil) + rr := httptest.NewRecorder() + + srv.serveFile(rr, req, "index.html") + + if rr.Code != http.StatusNotFound { + t.Fatalf("expected %d, got %d", http.StatusNotFound, rr.Code) + } +} + // ------------------------------------------------------------------ // Bootstrap negative paths // ------------------------------------------------------------------ |
