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

41 lines
1.7 KiB
Go

package main
import (
"os"
"strings"
"testing"
)
// R-1279 — the `.fab` import downloads first only if main.go passes the restores' helper in; an unwired exporter keeps
// the old order (volumes removed before the pull). Seam-built-but-never-wired is a recorded class (REUSE.md).
func TestR1279_MainWiresTheImportsDownloadFirst(t *testing.T) {
b, err := os.ReadFile("main.go")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(b), "appExporter.SetImagePreparer(backupMgr.PrepareRestoreImages)") {
t.Fatal("main.go must wire the import's download-first helper (SetImagePreparer)")
}
if !strings.Contains(string(b), "backupMgr.SetUnitSetAsideNotify(") {
t.Fatal("main.go must wire the D47 set-aside operator line")
}
if !strings.Contains(string(b), "func (a *stackAdapter) ContainerSamples(") {
t.Fatal("main.go's stack adapter must read container samples for the stable-start rule (fix A)")
}
}
// Fix A: the sampler reads a container with NO healthcheck (no State.Health) — measured on 9202: a -f template stopped
// at „map has no entry for key Health", so every such app read „not started".
func TestFixA_ParseContainerSamples(t *testing.T) {
out := []byte(`[{"Id":"a1","RestartCount":0,"State":{"Status":"running"}},
{"Id":"b2","RestartCount":3,"State":{"Status":"running","Health":{"Status":"healthy"}}},
{"Id":"c3","RestartCount":1,"State":{"Status":"restarting"}}]`)
got, err := parseContainerSamples(out)
if err != nil || len(got) != 3 {
t.Fatalf("parse: %v %+v", err, got)
}
if !got[0].Running || got[0].Health != "" || got[1].Health != "healthy" || got[1].RestartCount != 3 || got[2].Running {
t.Fatalf("wrong samples: %+v", got)
}
}