feat(statuspage): add nested status page groups and optional component details
ci / image (pull_request) Successful in 4m23s
ci / lint (pull_request) Canceled after 6m9s
ci / test (pull_request) Canceled after 6m8s
ci / build (pull_request) Canceled after 6m7s

This commit is contained in:
Sebastian Unterschütz committed 2026-11-22 20:07:30 +01:00
1 parent 1c31003baf
commit 9b26b4150e
26 files changed
+4566 -760

No files matched your search

+134
View File
@@ -299,3 +299,137 @@ func TestMaintenanceStartsWhileAPIIsDown(t *testing.T) {
t.Error("ended maintenance is still shown")
}
}
func TestNestedGroupsAndComponentDetails(t *testing.T) {
now := time.Date(2026, 11, 22, 12, 0, 0, 0, time.UTC)
hours := make([]agentapi.HourBucket, 24)
for i := range hours {
hours[i] = agentapi.HourBucket{
Time: now.Add(-time.Duration(23-i) * time.Hour),
Uptime: 1,
AvgLatencyMS: 35 + i,
}
}
snap := agentapi.PageSnapshot{
Slug: "acme",
Title: "Acme status",
Status: agentapi.PageDegraded,
ShowDetails: true,
GeneratedAt: now,
Sections: []agentapi.Section{
{
Name: "Platform",
Status: agentapi.PageDegraded,
Total: 2,
Children: []agentapi.Section{
{
Name: "API",
Status: agentapi.PageOutage,
Total: 1,
Components: []agentapi.Component{
{
ID: "comp-api",
Name: "Public API",
Status: agentapi.PageOutage,
Uptime: 0.995,
Days: []agentapi.Day{{Date: "2026-11-22", Uptime: 0.995}},
Details: &agentapi.ComponentDetails{
SLA24h: 0.99,
SLA7d: 0.995,
SLA30d: 0.998,
SLA90d: 0.995,
Hours: hours,
Regions: []agentapi.ComponentRegion{
{Name: "Frankfurt", Status: agentapi.PageOperational, LatencyMS: 42},
},
},
},
},
},
},
Components: []agentapi.Component{
{
ID: "comp-web",
Name: "Website",
Status: agentapi.PageOperational,
Uptime: 1,
Days: []agentapi.Day{{Date: "2026-11-22", Uptime: 1}},
},
},
},
},
Incidents: []agentapi.PageIncident{
{Component: "Public API", StartedAt: now.Add(-10 * time.Minute)},
},
}
src := &fakeSource{pages: map[string]agentapi.PageSnapshot{
"|acme": snap,
"status.acme.test|": snap,
}}
h := newHarness(t, src, t.TempDir(), &now)
t.Run("main page renders nested groups and clickable links", func(t *testing.T) {
code, body := h.get("status.example.test", "/acme")
if code != http.StatusOK {
t.Fatalf("GET /acme = %d, want 200", code)
}
for _, want := range []string{"<details open", "Platform", "API", `href="/acme/components/comp-api"`, `href="/acme/components/comp-web"`} {
if !strings.Contains(body, want) {
t.Errorf("GET /acme missing %q", want)
}
}
})
t.Run("component detail page on slug and custom domain", func(t *testing.T) {
cases := []struct {
name string
host string
path string
back string
}{
{name: "slug", host: "status.example.test", path: "/acme/components/comp-api", back: `href="/acme"`},
{name: "custom domain", host: "status.acme.test", path: "/components/comp-api", back: `href="/"`},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
code, body := h.get(tc.host, tc.path)
if code != http.StatusOK {
t.Fatalf("GET %s%s = %d, want 200", tc.host, tc.path, code)
}
for _, want := range []string{tc.back, "Public API", "Frankfurt", "42 ms", "<polyline", "Letzte 24 Stunden"} {
if !strings.Contains(body, want) {
t.Errorf("GET %s%s missing %q", tc.host, tc.path, want)
}
}
})
}
})
t.Run("unknown component returns 404", func(t *testing.T) {
if code, _ := h.get("status.example.test", "/acme/components/missing"); code != http.StatusNotFound {
t.Errorf("GET /acme/components/missing = %d, want 404", code)
}
})
t.Run("detail page stays available from cache during API outage", func(t *testing.T) {
src.set(func(f *fakeSource) { f.err = errors.New("connection refused") })
code, body := h.get("status.example.test", "/acme/components/comp-api")
if code != http.StatusOK || !strings.Contains(body, "Frankfurt") {
t.Errorf("GET cached detail during API outage = %d, want 200 with region data", code)
}
})
t.Run("detail page returns 404 when ShowDetails is disabled", func(t *testing.T) {
disabled := snap
disabled.ShowDetails = false
h2 := newHarness(t, &fakeSource{pages: map[string]agentapi.PageSnapshot{"|acme": disabled}}, t.TempDir(), &now)
code, body := h2.get("status.example.test", "/acme")
if code != http.StatusOK || strings.Contains(body, "/components/") {
t.Errorf("main page with ShowDetails=false = %d, unexpectedly links to /components/", code)
}
if code, _ := h2.get("status.example.test", "/acme/components/comp-api"); code != http.StatusNotFound {
t.Errorf("detail page with ShowDetails=false = %d, want 404", code)
}
})
}