Compare commits
2 Commits
ffba8f6257
...
de1e3f2190
| Author | SHA1 | Date | |
|---|---|---|---|
| de1e3f2190 | |||
| 310875368d |
@@ -364,14 +364,27 @@ func TestStaticFileRoute(t *testing.T) {
|
|||||||
cfg.StaticDir = "../../internal/static/"
|
cfg.StaticDir = "../../internal/static/"
|
||||||
router := createTestRouter(cfg)
|
router := createTestRouter(cfg)
|
||||||
|
|
||||||
|
t.Run("existing file should return 200", func(t *testing.T) {
|
||||||
request := httptest.NewRequest(http.MethodGet, "/static/css/main.css", nil)
|
request := httptest.NewRequest(http.MethodGet, "/static/css/main.css", nil)
|
||||||
recorder := httptest.NewRecorder()
|
recorder := httptest.NewRecorder()
|
||||||
|
|
||||||
router.ServeHTTP(recorder, request)
|
router.ServeHTTP(recorder, request)
|
||||||
|
|
||||||
if recorder.Code != http.StatusNotFound && recorder.Code != http.StatusOK {
|
if recorder.Code != http.StatusOK {
|
||||||
t.Errorf("Expected status 200 or 404 for static files, got %d", recorder.Code)
|
t.Errorf("Expected status 200 for existing static file, got %d", recorder.Code)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("non-existent file should return 404", func(t *testing.T) {
|
||||||
|
request := httptest.NewRequest(http.MethodGet, "/static/css/nonexistent.css", nil)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
|
||||||
|
router.ServeHTTP(recorder, request)
|
||||||
|
|
||||||
|
if recorder.Code != http.StatusNotFound {
|
||||||
|
t.Errorf("Expected status 404 for non-existent static file, got %d", recorder.Code)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterConfiguration(t *testing.T) {
|
func TestRouterConfiguration(t *testing.T) {
|
||||||
@@ -811,6 +824,9 @@ func TestQueryParameters(t *testing.T) {
|
|||||||
if recorder.Code == http.StatusNotFound {
|
if recorder.Code == http.StatusNotFound {
|
||||||
t.Errorf("Route %s %s should exist with query parameters, got 404", tc.method, fullPath)
|
t.Errorf("Route %s %s should exist with query parameters, got 404", tc.method, fullPath)
|
||||||
}
|
}
|
||||||
|
if recorder.Code >= http.StatusInternalServerError {
|
||||||
|
t.Errorf("Route %s %s should not return server error (5xx), got %d", tc.method, fullPath, recorder.Code)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user