package callstest import ( "net/http" "regexp" "strings" "testing" ) // hashedStylesheet is the fingerprinted URL shape the index page // links: /static/tokens.<16 hex>.css. var hashedStylesheet = regexp.MustCompile(`/static/tokens\.[0-9a-f]{16}\.css`) // hashedTheme is the same shape for the vendored theme sheet: // /static/theme.<16 hex>.css. var hashedTheme = regexp.MustCompile(`/static/theme\.[0-9a-f]{16}\.css`) func TestIndexRenders(t *testing.T) { c := newHarness(t, "paul@example.com").browser(t) c.signIn("paul@example.com") rec := c.get("/") if rec.Code != http.StatusOK { t.Fatalf("GET /: status %d, want 200", rec.Code) } if !strings.Contains(rec.Body.String(), "Meetings") { t.Errorf("GET /: page is missing its heading:\n%s", rec.Body.String()) } } // /signin renders the same layout as every other page and needs no // session, so it is what this test uses to find the fingerprinted // stylesheet links now that "/" requires one. Both the structural // tokens.css and the vendored theme.css must be there — a layout // linking only tokens.css is exactly the unstyled-live-site bug this // change fixes. func TestIndexLinksFingerprintedStylesheet(t *testing.T) { h := newApp(t) body := get(t, h, "/signin").Body.String() for _, re := range []*regexp.Regexp{hashedStylesheet, hashedTheme} { href := re.FindString(body) if href == "" { t.Fatalf("signed-out page links no fingerprinted asset matching %s", re) } rec := get(t, h, href) if rec.Code != http.StatusOK { t.Fatalf("GET %s: status %d, want 200", href, rec.Code) } if got := rec.Header().Get("Cache-Control"); got != "public, max-age=31536000, immutable" { t.Errorf("GET %s: Cache-Control = %q, want immutable year", href, got) } } } // The bare name keeps working, just never long-cached — so a changed // file always shows on an ordinary reload. func TestBareAssetNameStaysFresh(t *testing.T) { h := newApp(t) for _, name := range []string{"/static/tokens.css", "/static/theme.css"} { rec := get(t, h, name) if rec.Code != http.StatusOK { t.Fatalf("GET %s: status %d, want 200", name, rec.Code) } if got := rec.Header().Get("Cache-Control"); got != "no-cache" { t.Errorf("GET %s: Cache-Control = %q, want no-cache", name, got) } } }