package web
import (
"testing"
"craftdesign.group/quarry/internal/ci"
)
type workersEngine struct {
EngineViews
ws []ci.Worker
}
func (e workersEngine) Workers() ([]ci.Worker, error) { return e.ws, nil }
// A RUNNER ATTACHED TO A REPOSITORY IS LISTED ON IT.
//
// The engine reported no group for any registration, so a repository's
// Runners section said nobody was attached while its runner passed
// every run. dagnats v0.0.20 reports worker_groups; a worker counts for
// a repository when its group is among them, and as ungrouped only
// when it names none.
func TestARunnerIsListedUnderEveryGroupItDrains(t *testing.T) {
e := workersEngine{ws: []ci.Worker{
{WorkerID: "alpha-runner", WorkerGroups: []string{"alpha"}},
{WorkerID: "two-groups", WorkerGroups: []string{"beta", "alpha"}},
{WorkerID: "beta-runner", WorkerGroups: []string{"beta"}},
{WorkerID: "fleet"},
}}
mine, ungrouped := workersOf(e, "alpha")
var ids []string
for _, w := range mine {
ids = append(ids, w.WorkerID)
}
if len(ids) != 2 || ids[0] != "alpha-runner" || ids[1] != "two-groups" {
t.Errorf("FAIL: alpha lists %v", ids)
}
if ungrouped != 1 {
t.Errorf("FAIL: %d ungrouped, want 1", ungrouped)
}
}