carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package edgesfile
2
3import (
4 "encoding/json"
5 "testing"
6)
7
8// Region HA spec 2 §7: the placement policy reads the headroom totals and
9// the file's generation, so BoxChoice carries both.
10func TestBoxChoiceCarriesHeadroomTotalsAndGeneration(t *testing.T) {
11 var f PlacementView
12 body := `{"v":1,"box":"box-a","box_id":"i-a","generation":"2026-10-16T11:55:00Z","headroom":{"mem_free_mib":512,"disk_free_mib":2048,"mem_total_mib":4096,"disk_total_mib":20480,"awake":3},"hosts":{}}`
13 if err := json.Unmarshal([]byte(body), &f); err != nil {
14 t.Fatal(err)
15 }
16 f.Fresh = true
17 got := Snapshot{Files: []PlacementView{f}, Complete: true, BoxesComplete: true}.BoxChoice()
18 if len(got.Boxes) != 1 {
19 t.Fatalf("boxes %+v", got.Boxes)
20 }
21 b := got.Boxes[0]
22 if b.Generation != "2026-10-16T11:55:00Z" || b.Headroom == nil || b.Headroom.MemTotalMiB != 4096 || b.Headroom.DiskTotalMiB != 20480 || b.Headroom.MemFreeMiB != 512 || b.Headroom.DiskFreeMiB != 2048 || b.Headroom.Awake != 3 {
23 t.Fatalf("box lost a field: %+v %+v", b, b.Headroom)
24 }
25}
26