package inventory import ( "testing" "github.com/novox/mesh-controller/internal/broker" "github.com/novox/mesh-controller/internal/catalogue" ) // novox/hq issue 218: a seat held once for the mesh is granted and issued only to the holder on record; // a node seat to every machine's claimant; a mesh seat with no holder on record as derived. func TestOnlyTheRecordedHolderHoldsAMeshSeat(t *testing.T) { claimed := []broker.Seat{ {Name: "mesh-store", Scope: catalogue.ScopeMesh}, {Name: "node-packet-filter", Scope: catalogue.ScopeNode}, {Name: "unrecorded", Scope: catalogue.ScopeMesh}, } holdings := []catalogue.Held{{Claim: "mesh-store", Scope: catalogue.ScopeMesh, Node: "control", Module: "postgres"}} names := func(ss []broker.Seat) (out []string) { for _, s := range ss { out = append(out, s.Name) } return } if got := names(heldHere(claimed, holdings, "control", "postgres")); len(got) != 3 { t.Errorf("the holder lost a seat: %v", got) } got := names(heldHere(claimed, holdings, "other", "postgres")) if len(got) != 2 || got[0] != "node-packet-filter" || got[1] != "unrecorded" { t.Errorf("a claimant on another machine holds %v; want the node seat and the unrecorded one, not the store", got) } }