MCPcopy Index your code
hub / github.com/writefreely/writefreely / TestCacheControlForStaticFiles

Function TestCacheControlForStaticFiles

routes_test.go:12–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func 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}

Callers

nothing calls this directly

Calls 3

LoadConfigMethod · 0.95
InitStaticRoutesMethod · 0.95
NewAppFunction · 0.85

Tested by

no test coverage detected