package main import ( "testing" "github.com/novox/mesh-controller/internal/catalogue" ) // The overview of what a mesh has (novox/hq ADR 0110). func TestEverySeatIsListedIncludingTheOnesNobodyHolds(t *testing.T) { // An unheld seat is an answer — "this mesh has no forge" — so it is listed rather than omitted. rows, _ := seatsHeld(catalogue.Seats(), []catalogue.Held{ {Claim: "mesh-store", Scope: catalogue.ScopeMesh, Node: "anchor", Module: "postgres"}, }) if len(rows) != len(catalogue.Seats()) { t.Fatalf("%d seats listed of %d", len(rows), len(catalogue.Seats())) } for _, r := range rows { switch r.Seat { case "mesh-store": if len(r.Holders) != 1 || r.Holders[0].Module != "postgres" || r.Holders[0].Node != "anchor" { t.Errorf("mesh-store is held by %+v", r.Holders) } if r.Delivers != "postgres-database" { t.Errorf("mesh-store does not say what it delivers: %q", r.Delivers) } case "git": if len(r.Holders) != 0 { t.Errorf("git is held by %+v in a mesh with no forge", r.Holders) } } } } func TestANodeSeatListsEveryMachineHoldingIt(t *testing.T) { rows, _ := seatsHeld(catalogue.Seats(), []catalogue.Held{ {Claim: "node-packet-filter", Scope: catalogue.ScopeNode, Node: "node2", Module: "nftables"}, {Claim: "node-packet-filter", Scope: catalogue.ScopeNode, Node: "anchor", Module: "nftables"}, // Resolved twice, reported once: a machine is one holder however many passes saw it. {Claim: "node-packet-filter", Scope: catalogue.ScopeNode, Node: "anchor", Module: "nftables"}, }) for _, r := range rows { if r.Seat != "node-packet-filter" { continue } if len(r.Holders) != 2 || r.Holders[0].Node != "anchor" || r.Holders[1].Node != "node2" { t.Fatalf("the packet filter is held by %+v", r.Holders) } return } t.Fatal("the packet filter is not listed") } func TestAClaimOutsideTheSetIsShownNotHidden(t *testing.T) { // A manifest registered before the set closed can still hold one. Leaving it out would make // the overview quietly incomplete, which is the one thing it may not be. _, outside := seatsHeld(catalogue.Seats(), []catalogue.Held{ {Claim: "the-controller", Scope: catalogue.ScopeMesh, Node: "anchor", Module: "mesh-controller"}, }) if len(outside) != 1 || outside[0].Claim != "the-controller" { t.Fatalf("a claim outside the set was not shown: %+v", outside) } }