A controller that asked node-build-agent from its first run would queue every build where nothing pulls, and the build that registers build-agent — the first holder — would be among them. So the role is chosen at ask time from the catalogue: the current role when any assigned module claims it, the retired one while only the builder does, the current one when neither. Outcomes are followed on both seats, the controller may publish to both, and a build's log is read under whichever role did it; a machine on the retired role is proven on the bus to take that role's asks. The switch order is written where the role is named, and the retired half is marked for removal with the seat row.
44 lines
1.7 KiB
Go
44 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/catalogue"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
func claiming(module, seat string, on ...string) inventory.Entry {
|
|
return inventory.Entry{
|
|
Manifest: catalogue.Manifest{Module: module, Claims: []catalogue.Claim{{Name: seat}}},
|
|
On: on,
|
|
}
|
|
}
|
|
|
|
// The controller asks the build role that has a holder (novox/hq ADR 0190 handover): the retired
|
|
// one while only the builder is assigned, the current one from the first build-agent on, and the
|
|
// current one when nothing holds either — where every ask goes once the handover is done.
|
|
func TestTheControllerAsksTheBuildRoleThatHasAHolder(t *testing.T) {
|
|
onlyTheBuilder := []inventory.Entry{
|
|
claiming("builder", link.TheBuildMachineBefore, "anchor"),
|
|
claiming("build-agent", link.TheBuildMachine), // registered, assigned nowhere yet
|
|
}
|
|
if got := buildSeatAmong(onlyTheBuilder); got != link.TheBuildMachineBefore {
|
|
t.Errorf("with only the builder assigned, asked %q", got)
|
|
}
|
|
bothHeld := []inventory.Entry{
|
|
claiming("builder", link.TheBuildMachineBefore, "anchor"),
|
|
claiming("build-agent", link.TheBuildMachine, "home-server"),
|
|
}
|
|
if got := buildSeatAmong(bothHeld); got != link.TheBuildMachine {
|
|
t.Errorf("with a build-agent assigned anywhere, asked %q", got)
|
|
}
|
|
neither := []inventory.Entry{claiming("builder", link.TheBuildMachineBefore)}
|
|
if got := buildSeatAmong(neither); got != link.TheBuildMachine {
|
|
t.Errorf("with no holder of either, asked %q, want the current role", got)
|
|
}
|
|
if got := buildSeatAmong(nil); got != link.TheBuildMachine {
|
|
t.Errorf("an empty catalogue asks %q", got)
|
|
}
|
|
}
|