40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package localapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
// R-1192 follow-up (night 2026-10-21): GET /guest/memory carries the host's swap and this guest's swap allowance, so
|
|
// the controller's install page can say when the host has no swap behind the guest. 0 is a real answer (no swap);
|
|
// absent means an older agent.
|
|
// RED-PROOF: without the two MemoryInfo fields the keys are missing → fails on „host_swap_mb absent".
|
|
func TestR1192_GuestMemoryCarriesHostAndGuestSwap(t *testing.T) {
|
|
for _, c := range []struct {
|
|
name string
|
|
hostB, guestMB int64
|
|
wantHost, wantG int64
|
|
}{
|
|
{"installer host (7.75 GB swap), guest swap = RAM", 7935 * mib, 8192, 7935, 8192},
|
|
{"a host with NO swap", 0, 8192, 0, 8192},
|
|
} {
|
|
f := stdFixture()
|
|
f.hostSwapB, f.guestSwapMB = c.hostB, c.guestMB
|
|
w := do(t, memServer(t, f).Handler(), "GET", "/guest/memory", "A", "")
|
|
var m struct {
|
|
Data map[string]any `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
hs, ok := m.Data["host_swap_mb"].(float64)
|
|
if !ok {
|
|
t.Fatalf("%s: host_swap_mb absent: %s", c.name, w.Body.String())
|
|
}
|
|
gs, _ := m.Data["guest_swap_mb"].(float64)
|
|
if int64(hs) != c.wantHost || int64(gs) != c.wantG {
|
|
t.Fatalf("%s: host %v guest %v, want %d / %d", c.name, hs, gs, c.wantHost, c.wantG)
|
|
}
|
|
}
|
|
}
|