Skip to content
quarry Artifact [f74c24b279]
Login

Artifact [f74c24b279]

Artifact f74c24b2790ffd454e385a518051a3a31de805b6db39547f7a7b64f0a6ccbdc2:


package api

import "testing"

// An open landing's badge is its required checks' on the merge, not its
// branch's own run: green only when every one has passed, red when one
// failed, waiting while one has not answered.
func TestALandingIsGreenOnlyWhenItsRequiredChecksAre(t *testing.T) {
	const tip = "f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1"
	const trunk = "t0t0t0t0t0t0t0t0t0t0t0t0t0t0t0t0t0t0t0t0"
	pair := "pair:" + tip + ":" + trunk
	run := func(id, pipeline, status string) CIRun {
		return CIRun{RunID: id, Checkin: pair, Pair: pair, Workflow: "w." + id, Pipeline: pipeline, Status: status}
	}
	for _, c := range []struct {
		name     string
		runs     []CIRun
		required []string
		tip      string
		want     string
	}{
		{"both pass", []CIRun{run("q", "ci/quarry.json", "completed"), run("r", "ci/race.json", "completed")}, []string{"quarry", "race"}, "ci-pass", "ci-pass"},
		{"one running", []CIRun{run("q", "ci/quarry.json", "running"), run("r", "ci/race.json", "completed")}, []string{"quarry", "race"}, "ci-pass", "ci-waiting"},
		{"none yet", nil, []string{"quarry", "race"}, "ci-pass", "ci-waiting"},
		{"one failed", []CIRun{run("q", "ci/quarry.json", "failed"), run("r", "ci/race.json", "running")}, []string{"quarry", "race"}, "ci-pass", "ci-fail"},
		{"the branch failed", []CIRun{run("q", "ci/quarry.json", "completed")}, []string{"quarry"}, "ci-fail", "ci-fail"},
		{"nothing required", nil, nil, "ci-pass", "ci-pass"},
	} {
		ix := openLandingIndex(t, "feat", tip)
		l, open, err := ix.OpenLandingOn("feat")
		if err != nil || !open {
			t.Fatalf("no open landing: %v", err)
		}
		d := Deps{Repos: NewRepos(map[string]*Repo{"test": {Index: ix}}),
			CI:     pushedStub{pair: map[string][]CIRun{pair: c.runs}, latestPair: map[string]string{tip: pair}},
			Checks: checksStub{required: c.required}}
		if got := d.gatedVerdict("test", l, c.tip); got != c.want {
			t.Errorf("FAIL: %s: the badge is %q, want %q", c.name, got, c.want)
		}
	}
}