Files
uptimesebi/internal/ogimage/ogimage_test.go
T
Sebastian UnterschützandClaude Opus 5.5 3baeb98ee2
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m23s
ci / test (pull_request) Successful in 12m44s
ci / build (pull_request) Successful in 16m9s
ci / image (pull_request) Successful in 3m24s
feat(seo): metadata, previews and sitemaps for status pages and the app
Status pages describe themselves to search engines and link previews:
description (from the page's text, else its status), canonical address,
language versions via ?lang= with hreflang and x-default, Open Graph and
Twitter tags, and a 1200x630 preview image per page and language showing
its name and current status (/og.png). Each page has a sitemap.xml, and
robots.txt keeps crawlers off feeds, the API and subscription forms.
Component, legal and subscription pages are noindex.

In the cloud edition the app's sign-in, sign-up and legal pages get the
same tags with a preview image of their own, plus robots.txt and a
sitemap. Everything signed in stays noindex, and self-hosted
installations keep the whole app out of search engines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-28 22:50:34 +01:00

50 lines
1.3 KiB
Go

package ogimage
import (
"bytes"
"image/png"
"os"
"strings"
"testing"
)
func TestRender(t *testing.T) {
for _, c := range []Card{
{Title: "Hetzner Cloud", Subtitle: "All systems operational", Footer: "uptimesebi-status.net/hetzner", Accent: Up},
{Title: strings.Repeat("A very long status page name ", 6), Subtitle: strings.Repeat("problems ", 20), Footer: "x", Accent: Down},
{Title: ""},
} {
b, err := Render(c)
if err != nil {
t.Fatalf("Render(%q) error = %v", c.Title, err)
}
img, err := png.Decode(bytes.NewReader(b))
if err != nil {
t.Fatalf("Render(%q) is no PNG: %v", c.Title, err)
}
if r := img.Bounds(); r.Dx() != Width || r.Dy() != Height {
t.Errorf("Render(%q) size = %v, want %dx%d", c.Title, r, Width, Height)
}
if dir := os.Getenv("OGIMAGE_OUT"); dir != "" {
_ = os.WriteFile(dir+"/"+string(rune('a'+len(c.Title)%26))+".png", b, 0o600)
}
}
}
func TestWrap(t *testing.T) {
if err := loadFonts(); err != nil {
t.Fatal(err)
}
f, err := face(bold, 76)
if err != nil {
t.Fatal(err)
}
lines := wrap(f, strings.Repeat("word ", 100), 1040, 2)
if len(lines) != 2 || !strings.HasSuffix(lines[1], "…") {
t.Errorf("wrap() = %q, want two lines ending in an ellipsis", lines)
}
if got := wrap(f, "Short", 1040, 2); len(got) != 1 || got[0] != "Short" {
t.Errorf("wrap(Short) = %q", got)
}
}