After the build role moved to node-build-agent, nothing would hold it until build-agent is registered — and registering build-agent needs a build outcome that only the running builder could produce, bound as it was to the old seat by name. One binary, two roles: the seat a machine serves is the first its credential claims, as the mesh writes the claims beside the credential it issues (ADR 0159); the old builder keeps draining mesh-build-machine, a build-agent takes node-build-agent, and what each says about a build goes out as that seat's events, so an outcome is heard where the asker of that seat listens. A credential naming no claim serves the current role.
28 lines
993 B
Go
28 lines
993 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
// The seat a build machine serves comes from its credential (novox/hq ADR 0190 handover).
|
|
func TestTheCredentialSaysWhichBuildRoleThisMachineServes(t *testing.T) {
|
|
var held Credential
|
|
if err := json.Unmarshal([]byte(`{"url":"nats://bus:4222","user":"anchor.builder","password":"x",
|
|
"claims":[{"seat":"mesh-build-machine","scope":"mesh","serves":[]}]}`), &held); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := link.BuildSeatClaimed(held.seatsClaimed()); got != "mesh-build-machine" {
|
|
t.Errorf("the old builder's credential serves %q", got)
|
|
}
|
|
var bare Credential
|
|
if err := json.Unmarshal([]byte(`{"url":"nats://bus:4222","user":"anchor.build-agent","password":"x"}`), &bare); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := link.BuildSeatClaimed(bare.seatsClaimed()); got != link.TheBuildMachine {
|
|
t.Errorf("a credential without claims serves %q, want %s", got, link.TheBuildMachine)
|
|
}
|
|
}
|