(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestCacheControlForStaticFiles(t *testing.T) { |
| 13 | app := NewApp("testdata/config.ini") |
| 14 | if err := app.LoadConfig(); err != nil { |
| 15 | t.Fatalf("Could not create an app; %v", err) |
| 16 | } |
| 17 | router := mux.NewRouter() |
| 18 | app.InitStaticRoutes(router) |
| 19 | |
| 20 | rec := httptest.NewRecorder() |
| 21 | req := httptest.NewRequest("GET", "/style.css", nil) |
| 22 | router.ServeHTTP(rec, req) |
| 23 | if code := rec.Result().StatusCode; code != http.StatusOK { |
| 24 | t.Fatalf("Could not get /style.css, got HTTP status %d", code) |
| 25 | } |
| 26 | actual := rec.Result().Header.Get("Cache-Control") |
| 27 | |
| 28 | expectedDirectives := []string{ |
| 29 | "public", |
| 30 | "max-age", |
| 31 | "immutable", |
| 32 | } |
| 33 | for _, expected := range expectedDirectives { |
| 34 | if !strings.Contains(actual, expected) { |
| 35 | t.Errorf("Expected Cache-Control header to contain '%s', but was '%s'", expected, actual) |
| 36 | } |
| 37 | } |
| 38 | } |
nothing calls this directly
no test coverage detected