This repository has been archived on 2026-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mesh-controller/internal/catalogue/uplink_verbs_test.go
T
jochen 161e676b97 Give the uplink seat its verbs, staged until its holders serve them (hq ADR 0241)
What a machine resolves through and over which links had no tool: the
resolver file and its writer, and each link with its routes and resolvers,
are now verbs of node-uplink, the same whatever manages the network. A verb
required at once would refuse every holder before the catalogue could serve
it, and a stored one would be required by an older controller, so it is
staged: promised and routed, never stored, and not yet a condition of
holding.
2026-10-07 20:16:16 +02:00

69 lines
2.4 KiB
Go

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)
}
}
}