package grants import ( "slices" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" "git.novox.be/novox/mesh-sdk/go/seatdef" ) // The askers of a build seat's queue are read from the definition's callers lists (design 47 G §543, §600, A-163): a kind's // `stream` is its queue, a text callers names none, and only `seat:` entries are askers. func TestAcceptCallersOf(t *testing.T) { msg := func(name, stream string, callers ...string) seatdef.Message { m := seatdef.Message{Name: name, Stream: stream} if callers != nil { m.Callers = &seatdef.Callers{List: callers} } return m } got := acceptCallersOf(map[string]seatdef.Definition{ "node-build-go": {Seat: "node-build-go", PulledByKind: true, Accepts: []seatdef.Message{ msg("check", "", "seat:mesh-catalog", "operator"), msg("step", "check", "seat:mesh-pipeline-runner"), msg("delivery", "", "seat:mesh-builds"), {Name: "recheck", Callers: &seatdef.Callers{Text: "the checker"}}, }}, "other": {Seat: "other", Accepts: []seatdef.Message{msg("go", "", "seat:x")}}, }) if len(got) != 1 { t.Fatalf("seats: %v, want node-build-go alone", got) } q := got["node-build-go"] if !slices.Equal(q["check"], []string{"mesh-catalog", "mesh-pipeline-runner"}) || !slices.Equal(q["delivery"], []string{"mesh-builds"}) || len(q) != 2 { t.Errorf("queues: %v", q) } // A-170, A-184: the seat's workers are per queue, never per kind: step and run ride check or delivery. build := catalogue.SeatFromDefinition(seatdef.Definition{Seat: "node-build-go", PulledByKind: true, Accepts: []seatdef.Message{ msg("delivery", ""), msg("check", ""), msg("step", "check"), msg("step", "delivery"), msg("recheck", ""), msg("run", "check")}}) if got := queuesOf(build); !slices.Equal(got, []string{"delivery", "check", "recheck"}) { t.Errorf("the queues of %v on %v: %v, want delivery, check and recheck", build.Accepts, build.AcceptedOn, got) } }