Files
felhom-controller/controller/internal/monitor/r553_warning_kinds_test.go
T
admin fcd9f09927 health check: the last six producers carry their dashboard sentence (R-79 option A, D3)
Docker unreachable, protected container down, and the four storage-path entries now carry a
bundle key beside their wire text; the wire text is unchanged byte for byte. Hungarian values of
the four storage keys equal the frozen formats (i18n_go_parity). Red-proven: a zero MsgRef on the
unavailable-path warning fails TestR79_RemainingProducersCarryTheirDashboardSentence and
TestR79_HealthBannersFollowTheHousehold (producer-driven, English household sees Hungarian).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-10-08 14:49:27 +02:00

75 lines
3.1 KiB
Go

package monitor
import (
"os"
"path/filepath"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
)
// R-553 — the storage warnings carry a KIND, and their sentences are byte-for-byte unchanged.
//
// checkStoragePaths is the real producer the health check folds into the report. The kinds are what
// the dashboard reads to decide WHERE a warning is shown; the sentence is what the household reads.
//
// RED-PROOF (REPORT): drop the `kinds = append(…, WarnKindStorageNotSeparate)` line and the
// placement test in internal/web fails with the warning back in the top banner.
func TestR553_StorageWarningsCarryKindsAndKeepTheirWords(t *testing.T) {
dir := t.TempDir()
present := filepath.Join(dir, "data")
if err := os.MkdirAll(present, 0o755); err != nil {
t.Fatal(err)
}
paths := []settings.StoragePath{
{Path: filepath.Join(dir, "gone"), Label: "Leválasztott", Disconnected: true},
{Path: filepath.Join(dir, "nem-letezik")},
{Path: present},
{Path: filepath.Join(dir, "kihagyott"), Decommissioned: true},
}
_, _, warnings, kinds, _ := checkStoragePaths(paths)
if len(warnings) != len(kinds) {
t.Fatalf("a warning without its kind (or the reverse): %d warnings, %d kinds", len(warnings), len(kinds))
}
want := []struct{ text, kind string }{
{"Meghajtó leválasztva: Leválasztott (" + filepath.Join(dir, "gone") + ")", WarnKindStorageDisconnected},
{"Adattároló nem elérhető: " + filepath.Join(dir, "nem-letezik"), WarnKindStorageUnavailable},
{"Az adattároló (" + present + ") nem külön meghajtón van — az adatok a rendszermeghajtóra íródnak", WarnKindStorageNotSeparate},
}
if len(warnings) != len(want) {
t.Fatalf("warnings = %q, want %d of them", warnings, len(want))
}
for i, w := range want {
if warnings[i] != w.text {
t.Errorf("warning %d CHANGED:\n got %q\nwant %q", i, warnings[i], w.text)
}
if kinds[i] != w.kind {
t.Errorf("warning %d has kind %q, want %q", i, kinds[i], w.kind)
}
}
// The decommissioned path is skipped entirely — it must not appear with an empty kind either.
for i, w := range warnings {
if kinds[i] == "" {
t.Errorf("storage warning %q carries no kind — the dashboard would fall back to placing it in the banner", w)
}
}
}
// A warning and its kind can never drift apart, because every warning goes through addWarning.
func TestR553_WarningKindsStayParallel(t *testing.T) {
r := &HealthReport{}
r.addWarning("CPU usage high: 91%", "")
r.addWarning("Az adattároló (/mnt/x) nem külön meghajtón van", WarnKindStorageNotSeparate)
if len(r.Warnings) != 2 || len(r.WarningKinds) != 2 {
t.Fatalf("lengths drifted: %d warnings, %d kinds", len(r.Warnings), len(r.WarningKinds))
}
if r.WarningKindAt(0) != "" || r.WarningKindAt(1) != WarnKindStorageNotSeparate {
t.Errorf("kinds read back wrong: %q, %q", r.WarningKindAt(0), r.WarningKindAt(1))
}
// A report built by hand (an older caller, a test fixture) answers "" instead of panicking.
old := &HealthReport{Warnings: []string{"x"}}
if old.WarningKindAt(0) != "" || old.WarningKindAt(9) != "" {
t.Error("a report with no kinds must answer \"\", never index out of range")
}
}