package catalogue import ( "slices" "strings" "testing" ) // The node-uplink seat's verbs (novox/hq ADR 0241): promised and routed, staged — not yet a condition of // holding — so the holders of today still hold it, a holder may name them, and nothing it does not promise. func uplinkSeat(t *testing.T) Seat { t.Helper() for _, s := range DefaultSeats() { if s.Name == "node-uplink" { return s } } t.Fatal("no node-uplink seat") return Seat{} } func TestTheUplinkSeatPromisesItsVerbsAndRequiresNoneYet(t *testing.T) { seat := uplinkSeat(t) var names []string for _, v := range seat.Serves { names = append(names, v.Name) } if !slices.Equal(names, []string{"resolvers", "links"}) || len(seat.Required()) != 0 { t.Fatalf("node-uplink promises %v and requires %v", names, seat.Required()) } today := Manifest{Module: "networkmanager", Version: "1", Claims: []Claim{{Name: "node-uplink", Scope: ScopeNode}}} if err := CanHold(today, seat); err != nil { t.Fatalf("a holder that serves no verb yet is refused: %v", err) } serving := today serving.Claims = []Claim{{Name: "node-uplink", Scope: ScopeNode, Serves: []string{"resolvers", "links"}}} if err := CanHold(serving, seat); err != nil { t.Fatalf("a holder serving both is refused: %v", err) } typo := today typo.Claims = []Claim{{Name: "node-uplink", Scope: ScopeNode, Serves: []string{"resolver"}}} if err := CanHold(typo, seat); err == nil || !strings.Contains(err.Error(), "does not promise") { t.Fatalf("a verb the seat does not promise was accepted: %v", err) } } func TestAStagedVerbIsNeverStoredAndComesBackFromTheBinary(t *testing.T) { seat := uplinkSeat(t) if stored := seat.Stored(); len(stored.Serves) != 0 { t.Fatalf("the row would keep %v", stored.Serves) } before := seats t.Cleanup(func() { seats = before }) // A row as the store keeps it: no protocol of its own. And one an operator gave a verb of its own. UseSeats([]Seat{{Name: "node-uplink", Scope: ScopeNode}, {Name: "node-service-manager", Scope: ScopeNode}}) for _, s := range Seats() { if s.Name == "node-uplink" && (len(s.Serves) != 2 || len(s.Staged) != 2) { t.Fatalf("the working set's node-uplink is %+v", s) } } UseSeats([]Seat{{Name: "node-uplink", Scope: ScopeNode, Serves: []Verb{{Name: "operators-own"}}}}) for _, s := range Seats() { if s.Name == "node-uplink" && len(s.Serves) != 3 { t.Fatalf("a row with a verb of its own lost or did not gain the staged ones: %+v", s.Serves) } } }