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