diff --git a/internal/site/build_test.go b/internal/site/build_test.go index caf8891..b6bd0b1 100644 --- a/internal/site/build_test.go +++ b/internal/site/build_test.go @@ -2,6 +2,7 @@ package site import ( "encoding/json" + "encoding/xml" "io/fs" "net/url" "os" @@ -311,3 +312,122 @@ func TestTheBrokersCsvIsNeverPublished(t *testing.T) { } } } + +func cards(t *testing.T, public string) map[string]string { + t.Helper() + found := map[string]string{} + err := filepath.WalkDir(public, func(path string, entry fs.DirEntry, err error) error { + if err == nil && !entry.IsDir() && entry.Name() == "ogp.svg" { + rel, _ := filepath.Rel(public, path) + found[filepath.ToSlash(rel)] = read(t, public, filepath.ToSlash(rel)) + } + return err + }) + if err != nil { + t.Fatal(err) + } + return found +} + +func TestEveryCardIsWellFormedSvgOfTheSizeOfAnOgpImage(t *testing.T) { + found := cards(t, build(t, true)) + if len(found) < 3+len(pnlDays(t)) { + t.Fatalf("%d cards", len(found)) + } + for name, svg := range found { + var doc struct { + Width string `xml:"width,attr"` + Height string `xml:"height,attr"` + } + if err := xml.Unmarshal([]byte(svg), &doc); err != nil { + t.Errorf("%s: %v", name, err) + continue + } + if doc.Width != "1200" || doc.Height != "630" { + t.Errorf("%s: %sx%s", name, doc.Width, doc.Height) + } + if strings.Contains(svg, "", "2026-11-09"} { + if !strings.Contains(card, want) { + t.Errorf("the card lacks %q", want) + } + } + if strings.Count(card, `font-size="68"`) > 3 { + t.Error("more than three title lines") + } +} + +func TestTheDockerfileConvertsEveryCardAndFailsIfOneIsLeft(t *testing.T) { + data, err := os.ReadFile(filepath.Join(root(t), "Dockerfile")) + if err != nil { + t.Fatal(err) + } + for _, want := range []string{"rsvg-convert", "font-noto-cjk", `-name ogp.svg`, `test -z "$(find /public -name ogp.svg)"`} { + if !strings.Contains(string(data), want) { + t.Errorf("the Dockerfile lacks %q", want) + } + } +}