Files
felhom-controller/controller/cmd/controller/r521_f7_rootfs_test.go
T

69 lines
2.8 KiB
Go

package main
import (
"io"
"log"
"path/filepath"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/config"
"gitea.dooplex.hu/admin/felhom-controller/internal/fillwatch"
"gitea.dooplex.hu/admin/felhom-controller/internal/system"
)
type fillPushRecord struct {
eventType, severity, message, household string
details interface{}
}
type fakeFillPusher struct{ got []fillPushRecord }
func (f *fakeFillPusher) PushEventHousehold(eventType, severity, message, household string, details interface{}) {
f.got = append(f.got, fillPushRecord{eventType, severity, message, household, details})
}
// R-521 F7 (BIGNIGHT 2026-09-14): the guest's own system disk at 95 % produced only `health_degraded`,
// whose mail a cooldown swallowed — no disk-specific event reached the hub. The consequence pinned here,
// through the REAL target list (fillTargets), the REAL watcher and the REAL push closure (fillEventPush):
// the guest's root filesystem at F7's numbers sends the hub's existing `disk_critical` event (severity
// critical, a type the hub already allowlists), ONCE (edge-triggered), carrying the Hungarian sentence
// AND the household's own (English here).
func TestR521F7_RootFilesystemSendsTheDiskEventInBothLanguages(t *testing.T) {
cfg := &config.Config{}
cfg.Paths.SystemDataPath = "/mnt/sys_drive"
usage := func(p string) *fillwatch.Usage {
if p == system.DockerVolumePath { // the guest's root filesystem as the controller sees it
return &fillwatch.Usage{UsedPercent: 95, AvailGB: 3.5, UsedGB: 61.8, TotalGB: 68.7}
}
return &fillwatch.Usage{UsedPercent: 30, AvailGB: 50, UsedGB: 20, TotalGB: 70}
}
w := fillwatch.New(filepath.Join(t.TempDir(), "fill.json"), log.New(io.Discard, "", 0),
func() []fillwatch.Target { return fillTargets(cfg, nil) }, usage)
rec := &fakeFillPusher{}
w.SetNotify(fillEventPush(rec))
w.SetLang(func() string { return "en" })
for i := 0; i < 2; i++ { // the second check sees the same band: nothing new (edge-triggered)
if err := w.Check(); err != nil {
t.Fatal(err)
}
}
if len(rec.got) != 1 {
t.Fatalf("pushes = %d (%+v), want exactly 1 disk event for the root filesystem", len(rec.got), rec.got)
}
p := rec.got[0]
if p.eventType != "disk_critical" || p.severity != "critical" {
t.Errorf("pushed %s/%s, want disk_critical/critical", p.eventType, p.severity)
}
if d, _ := p.details.(map[string]any); d == nil || d["path"] != system.DockerVolumePath {
t.Errorf("details = %v, want path %q", p.details, system.DockerVolumePath)
}
if !strings.Contains(p.message, "Alkalmaz") || !strings.Contains(p.message, "kritikusan") {
t.Errorf("Hungarian message = %q", p.message)
}
if !strings.Contains(p.household, "App area") || !strings.Contains(p.household, "critically full") {
t.Errorf("household (English) message = %q", p.household)
}
}