Skip to content
quarry Artifact [ae085e6405]
Login

Artifact [ae085e6405]

Artifact ae085e6405bde7d0c6459304f61163b3deb2a33dacad07516498ceaa97c2a574:


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