//go:build integration package main import ( "testing" "time" "github.com/novox/mesh-controller/internal/catalogue" "github.com/novox/mesh-controller/internal/inventory" ) func TestAWalksClassAndWindowAreReadAtItsCut(t *testing.T) { entries := []inventory.Entry{ {Manifest: catalogue.Manifest{Module: "dnsmasq", Claims: []catalogue.Claim{{Name: resolverSeat}}}}, {Manifest: catalogue.Manifest{Module: "gitea"}}, } walk := func(modules ...string) inventory.Plan { p := inventory.Plan{Modules: map[string]*inventory.PlanModule{}} for _, m := range modules { p.Modules[m] = &inventory.PlanModule{} } return p } for want, w := range map[string]inventory.Plan{ inventory.ClassLeaf: walk("gitea"), inventory.ClassCore: walk("gitea", "mesh-controller"), } { if got := classOf(w, entries); got != want { t.Errorf("%v: %s, want %s", w.Modules, got, want) } } if got := classOf(walk("dnsmasq"), entries); got != inventory.ClassCore { t.Errorf("the resolver's holder is core: %s", got) } now := time.Date(2026, 10, 10, 18, 0, 0, 0, time.UTC) batch := inventory.Plan{Delivery: &inventory.PlanDelivery{Batch: &inventory.PlanBatch{ ClosesAt: now.Add(-20 * time.Second), AtMost: now.Add(5 * time.Minute)}}} times := walkTimesAtCut(batch, walk("gitea"), entries, now) if times.Cut == nil || !times.Cut.Equal(now) || times.WindowClosed == nil || !times.WindowClosed.Equal(now.Add(-20*time.Second)) || times.Class != inventory.ClassLeaf { t.Fatalf("times at the cut: %+v", times) } batch.Delivery.Batch.AtMost = now.Add(-time.Minute) if times := walkTimesAtCut(batch, walk("gitea"), entries, now); !times.WindowClosed.Equal(now.Add(-time.Minute)) { t.Fatalf("a window closed at its maximum: %v", times.WindowClosed) } if times := walkTimesAtCut(inventory.Plan{Delivery: &inventory.PlanDelivery{Alone: true}}, walk("gitea"), entries, now); times.WindowClosed != nil { t.Fatalf("a merge walked alone had no window: %v", times.WindowClosed) } }