check / check (push) Waiting to run
version.License, which the home and status page footers show, still said WTFPL after LICENSE and the README moved to MIT. It now says MIT. A test renders both pages and expects each footer to name MIT and not WTFPL. Model: opus-5-5
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package templates_test
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.eeqj.de/sneak/routewatch/internal/templates"
|
|
)
|
|
|
|
// TestFooterLicense renders the home and status pages and expects each footer
|
|
// to name the licence in LICENSE, MIT, and not WTFPL.
|
|
func TestFooterLicense(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
const (
|
|
license = "MIT"
|
|
wrongLicense = "WTFPL"
|
|
)
|
|
|
|
pages := map[string]*template.Template{
|
|
"index": templates.IndexTemplate(),
|
|
"status": templates.StatusTemplate(),
|
|
}
|
|
|
|
for name, tmpl := range pages {
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var page bytes.Buffer
|
|
|
|
err := tmpl.Execute(&page, struct{ CSPNonce string }{})
|
|
if err != nil {
|
|
t.Fatalf("rendering the page: %v", err)
|
|
}
|
|
|
|
_, footer, found := strings.Cut(page.String(), "<footer")
|
|
if !found {
|
|
t.Fatal("the page has no footer")
|
|
}
|
|
|
|
footer, _, _ = strings.Cut(footer, "</footer>")
|
|
|
|
if !strings.Contains(footer, license) {
|
|
t.Errorf("footer does not name %s: %q", license, footer)
|
|
}
|
|
|
|
if strings.Contains(footer, wrongLicense) {
|
|
t.Errorf("footer names %s: %q", wrongLicense, footer)
|
|
}
|
|
})
|
|
}
|
|
}
|