package hub import ( "bytes" "log/slog" "strings" "testing" "gitea.dooplex.hu/admin/felhom-agent/internal/proxmox" ) // R-1192 follow-up (night 2026-10-21): the host report carries the host's swap and the guests' swap allowance, and the // agent says ONCE in its log when the host's swap is below it (and once when it is covered again). // RED-PROOF: with applySwap not called the numbers are nil; with the CompareAndSwap removed the WARN repeats. func TestR1192_HostReportCarriesSwapAndWarnsOnce(t *testing.T) { var buf bytes.Buffer c := &Collector{logger: slog.New(slog.NewTextHandler(&buf, nil))} guests := []Guest{{VMID: 9201, Spec: &GuestSpec{SwapBytes: 4096 << 20}}, {VMID: 9202, Spec: nil}} var ns proxmox.NodeStatus // a host with no swap for i := 0; i < 3; i++ { h := HostMetrics{} c.applySwap(&h, ns, guests) if h.HostSwapMB == nil || h.GuestSwapMB == nil || *h.HostSwapMB != 0 || *h.GuestSwapMB != 4096 { t.Fatalf("report numbers: host %v guest %v", h.HostSwapMB, h.GuestSwapMB) } } if n := strings.Count(buf.String(), "host-swap: the host's swap is below"); n != 1 { t.Fatalf("the short WARN must be logged once, got %d:\n%s", n, buf.String()) } ns.Swap.Total = 7935 << 20 // the installer's 8 GB host h := HostMetrics{} c.applySwap(&h, ns, guests) if *h.HostSwapMB != 7935 || HostSwapShort(*h.HostSwapMB, *h.GuestSwapMB) { t.Fatalf("a covered host must not be short: %v / %v", *h.HostSwapMB, *h.GuestSwapMB) } if !strings.Contains(buf.String(), "covers its guests' swap allowance again") { t.Fatalf("the recovery must be said once:\n%s", buf.String()) } if HostSwapShort(0, 0) { t.Fatal("a host whose guests have no swap allowance is never short") } }