Skip to content
quarry Artifact [34798f51ae]
Login

Artifact [34798f51ae]

Artifact 34798f51ae7e24db867b893fe5ea249251a49408b6e26a86aa7409a26cc4f2ef:


package api

import "testing"

// A landed merge with no verdict tag yet: its own runs going read as
// being checked, an inherited verdict reads as the verdict it already
// is, and nothing at all says nothing.
func TestMergeVerdictOfRuns(t *testing.T) {
	for _, tc := range []struct {
		name      string
		runs      []CIRun
		want, run string
	}{
		{"inherited pass, tag not yet written", []CIRun{
			{RunID: "p1", Status: "completed", InheritedFrom: "p1"},
			{RunID: "p2", Status: "completed", InheritedFrom: "p2"},
		}, "ci-pass", "p2"},
		{"inherited fail", []CIRun{
			{RunID: "p1", Status: "completed", InheritedFrom: "p1"},
			{RunID: "p2", Status: "failed", InheritedFrom: "p2"},
		}, "ci-fail", "p2"},
		{"a run of its own still going", []CIRun{
			{RunID: "p1", Status: "completed", InheritedFrom: "p1"},
			{RunID: "r9", Status: "running"},
		}, "ci-run", "r9"},
		{"a failure outranks a run going", []CIRun{
			{RunID: "r9", Status: "running"},
			{RunID: "p2", Status: "failed", InheritedFrom: "p2"},
		}, "ci-fail", "p2"},
		{"completed and cancelled runs say nothing", []CIRun{
			{RunID: "r1", Status: "completed", Completed: "2026-10-12T00:00:00Z"},
			{RunID: "r2", Status: "cancelled"},
		}, "", ""},
	} {
		v, run := mergeVerdictOfRuns(tc.runs)
		if v != tc.want || run != tc.run {
			t.Errorf("FAIL: %s: got %q %q, want %q %q", tc.name, v, run, tc.want, tc.run)
		}
	}
	t.Log("ok: an inherited verdict is read as itself, not as a run going")
}