Files
felhom.eu/hub/internal/web/funcmap_test.go
T
admin bc8d54df6a D4 Part 1: hub fonts + sprite + statusColor semantic remap
- static/fonts/: the 4 vendored woff2 (byte-copied from
  felhom-controller), embedded (embed.go) and served at /static/fonts/
  (font/woff2, immutable) mirroring the chart.min.js pattern. No CDN
  before, none now.
- templates/icons.html: 12-symbol Lucide sprite partial (icon_sprite),
  included at the top of <body> on all 9 pages ({{template}} — the hub
  has no shared layout; per-page include is the minimal shared block).
- statusColor now returns v2 semantic tokens (nominal/warn/crit/
  neutral) consumed as class suffixes: ok->nominal, warn+stale->warn,
  down+fail->crit, pending+disabled->neutral (a not-yet-provisioned or
  deliberately paused customer is a normal fleet state), blocked->warn
  (intentional operator cut-off, attention-worthy not an outage),
  unknown->neutral. The inline style="color: {{statusColor}}" pattern
  is dead: dashboard + customer_unified render a class-based
  .status-dot-<token>; statusIcon (constant "●") retired from funcmap
  and templates.
- Tests (new; the hub web package had no funcmap/template tests):
  TestStatusColorTruthTable over the full enumerated status set —
  red-proven vs the old implementation (ok returned "#4ade80") — and
  TestTemplatesParseWithFuncmap.
2026-07-02 22:34:40 +02:00

57 lines
2.3 KiB
Go

package web
import (
"html/template"
"testing"
)
// TASK-D4 §7B: statusColor maps every OverallStatus value the hub emits (server.go
// handleDashboard + configs.go + the hosts stale state) to a v2 semantic token consumed
// as a class suffix — never an inline color. Exception-color: healthy fleet = blue/neutral.
func TestStatusColorTruthTable(t *testing.T) {
cases := []struct {
status string
want string
}{
{"ok", "nominal"}, // operating normally — blue
{"warn", "warn"}, // degraded / stale report — amber
{"stale", "warn"}, // host stale state
{"down", "crit"}, // outage — red
{"fail", "crit"}, // health=fail — red
{"pending", "neutral"}, // not-yet-provisioned customer is a NORMAL fleet state
{"disabled", "neutral"}, // deliberately paused — not a deviation
{"blocked", "warn"}, // operator cut-off: intentional but attention-worthy
{"bogus", "neutral"}, // unknown values stay quiet
{"", "neutral"},
}
for _, c := range cases {
if got := statusColor(c.status); got != c.want {
t.Errorf("statusColor(%q) = %q, want %q", c.status, got, c.want)
}
}
}
// TestTemplatesParseWithFuncmap parses all hub templates with the production funcmap —
// catches a typo'd function name introduced during the D4 sweep (did not exist before).
func TestTemplatesParseWithFuncmap(t *testing.T) {
s := New(nil, "", "", "test", 0, nil)
_ = s // New itself template.Must-parses; reaching here means parse succeeded
// belt and braces: parse again explicitly
if _, err := template.New("").Funcs(template.FuncMap{
"timeAgo": timeAgo,
"timeAgoPtr": func(v interface{}) string { return "" },
"statusColor": statusColor,
"formatFloat": func(f float64) string { return "" },
"joinStrings": func(s []string, sep string) string { return "" },
"json": func(v interface{}) template.JS { return "" },
"hubVersion": func() string { return "" },
"add": func(a, b int) int { return 0 },
"mapGet": func(m map[string]int, k string) int { return 0 },
"memoryColor": memoryColor,
"accuracyClass": accuracyClass,
"gt": func(a, b int) bool { return false },
}).ParseFS(templateFS, "templates/*.html"); err != nil {
t.Fatalf("templates failed to parse: %v", err)
}
}