Skip to content
quarry Artifact [112b5bf22d]
Login

Artifact [112b5bf22d]

Artifact 112b5bf22dd2cf5bf597aa6af34db45d519d331abeaab7c86d3a2b596a76993a:


package main

import (
	"path/filepath"
	"slices"
	"testing"

	"craftdesign.group/quarry/internal/oltp"
)

// A pipeline counts as run at a check-in only when its run has, or
// will have, a verdict. A cancelled run never reports and a deferred
// one has not started, so an opened landing still owes both.
func TestRunPipelinesListsOnlyRunsThatWillHaveAVerdict(t *testing.T) {
	db, err := oltp.Open(filepath.Join(t.TempDir(), "oltp.db"))
	if err != nil {
		t.Fatal(err)
	}
	defer db.Close()
	st := ciStore{db: db}
	for _, r := range []oltp.CIRun{
		{RunID: "r1", Repo: "alpha", Checkin: "tip", Workflow: "w", Pipeline: "ci/quarry.json", Status: "cancelled"},
		{RunID: "r2", Repo: "alpha", Checkin: "tip", Workflow: "w", Pipeline: "ci/race.json", Status: "deferred"},
		{RunID: "r3", Repo: "alpha", Checkin: "tip", Workflow: "w", Pipeline: "ci/lint.json", Status: "running"},
		{RunID: "r4", Repo: "alpha", Checkin: "tip", Workflow: "w", Pipeline: "ci/docs.json", Status: "failed"},
		{RunID: "r5", Repo: "alpha", Checkin: "other", Workflow: "w", Pipeline: "ci/quarry.json", Status: "completed"},
	} {
		if err := db.AddCIRun(r); err != nil {
			t.Fatal(err)
		}
	}
	got, err := st.RunPipelines("alpha", "tip")
	if err != nil {
		t.Fatal(err)
	}
	slices.Sort(got)
	if want := []string{"ci/docs.json", "ci/lint.json"}; !slices.Equal(got, want) {
		t.Errorf("FAIL: RunPipelines = %v, want %v (cancelled and deferred runs are no verdict)", got, want)
	}
	t.Log("ok: cancelled and deferred runs leave their pipeline owed")
}