Skip to content
quarry Artifact [db3448afc1]
Login

Artifact [db3448afc1]

Artifact db3448afc13fe174e080c97e33cf7699cd68114cec5316a427f17a51e083cff3:


package api

import (
	"reflect"
	"testing"
)

// Opening a landing asks for a run only where nothing has reported.
// The distinction that matters: a cancelled run is not a verdict, a
// failed one is.
func TestWhichChecksHaveNoVerdict(t *testing.T) {
	req := []string{"quarry", "lint"}
	for _, c := range []struct {
		name     string
		runs     []CIRun
		reported []string
		want     []string
	}{
		{name: "nothing has run at all", want: []string{"quarry", "lint"}},
		{
			name: "a cancelled run is not a verdict",
			runs: []CIRun{{Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "cancelled"}},
			want: []string{"quarry", "lint"},
		},
		{
			name: "a failure IS a verdict — re-running would bury it",
			runs: []CIRun{{Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "failed"}},
			want: []string{"lint"},
		},
		{
			name: "a run still in flight is an answer on the way",
			runs: []CIRun{{Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "running"}},
			want: []string{"lint"},
		},
		{
			name: "a pass settles it",
			runs: []CIRun{{Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "completed"}},
			want: []string{"lint"},
		},
		{
			name:     "somebody else's reporter counts",
			reported: []string{"lint"},
			runs:     []CIRun{{Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "completed"}},
			want:     nil,
		},
		{
			name: "a cancelled run beside a later real one is answered",
			runs: []CIRun{
				{Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "cancelled"},
				{Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "failed"},
			},
			want: []string{"lint"},
		},
	} {
		t.Run(c.name, func(t *testing.T) {
			got := withoutVerdict(req, c.runs, c.reported)
			if !reflect.DeepEqual(got, c.want) {
				t.Errorf("FAIL: got %v, want %v", got, c.want)
			}
		})
	}
}

// No required checks means nothing to ask for: a repository that has
// configured none must never have a run fired at it by opening a
// landing.
func TestNoRequiredChecksAsksForNothing(t *testing.T) {
	if got := withoutVerdict(nil, nil, nil); got != nil {
		t.Errorf("FAIL: got %v, want nothing", got)
	}
}