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