50 lines
1.9 KiB
Go
50 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-controller/internal/busymark"
|
|
"gitea.dooplex.hu/admin/felhom-controller/internal/config"
|
|
)
|
|
|
|
// D65 = A: the agent reads ONE fixed guest path — the controller-data volume + data/ctl/busy
|
|
// (felhom-agent ControllerBusyMarkerGuestPath, and its sudoers line). The volume is mounted at
|
|
// /opt/docker/felhom-controller, so the controller must write <default data dir>/ctl/busy.
|
|
// RED-PROOF: rename holdCtlDir or busymark.FileName → the path moves → FAILS.
|
|
func TestBusyMarkPathIsTheOneTheAgentReads(t *testing.T) {
|
|
cfg, err := config.LoadFromBytes([]byte("customer:\n id: t\n domain: t.example\n"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := filepath.Join(cfg.Paths.DataDir, holdCtlDir, busymark.FileName)
|
|
want := "/opt/docker/felhom-controller/data/ctl/busy" // = the agent's /var/lib/docker/volumes/felhom-controller-data/_data/data/ctl/busy
|
|
if got != want {
|
|
t.Fatalf("the busy file is %s, the agent reads %s — an operator reboot would never be refused for a backup", got, want)
|
|
}
|
|
}
|
|
|
|
// Every kind of work has its probe and the writer is started — a seam built and never wired is this project's commonest
|
|
// defect. RED-PROOF: delete any AddProbe line or the Run → FAILS.
|
|
func TestBusyMarkIsWiredAtStartup(t *testing.T) {
|
|
raw, err := os.ReadFile("main.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
src := string(raw)
|
|
for _, want := range []string{
|
|
`busyMark.AddProbe("an app update is running", stackMgr.AnyUpdating)`,
|
|
`return backupMgr.IsRunning() || backupMgr.RestoreStatus().Running`,
|
|
`busyMark.AddProbe("the night backup catch-up is running", catchUp.Running)`,
|
|
`busyMark.AddProbe("an app export or import is running", appExporter.IsRunning)`,
|
|
`go busyMark.Run(ctx)`,
|
|
`go webServer.WatchOperatorReboot(ctx)`, // the household line after an operator reboot
|
|
} {
|
|
if !strings.Contains(src, want) {
|
|
t.Fatalf("main.go does not contain %q", want)
|
|
}
|
|
}
|
|
}
|