Skip to content
quarry Artifact [bb9b524af6]
Login

Artifact [bb9b524af6]

Artifact bb9b524af6db48f51cbe68ddf88a0bacb3b21b8883efe7ce4a46d3499f54554b:


package api

import "testing"

// A required check is named by a person, so it has to match the name a
// person would use. Registering a workflow under a repository-scoped
// name with a digest broke this on production: the required check on
// trunk is called "quarry" and the workflow became
// "quarry.quarry.574cf8", so the check matched nothing green and every
// landing on trunk would have reported it unmet.
func TestARequiredCheckMatchesThePipelinesOwnName(t *testing.T) {
	for _, tc := range []struct{ path, want, why string }{
		{"ci/quarry.json", "quarry", "the name a required check is configured with"},
		{"ci/build.yml", "build", "yaml the same way"},
		{"ci/check.yaml", "check", "the longer extension too"},
		{"quarry.json", "quarry", "no directory"},
		{"ci/no-extension", "no-extension", "a name with no extension is its own stem"},
		{"ci/two.parts.yml", "two.parts", "only the last extension goes"},
		{"", "", "nothing in, nothing out"},
	} {
		if got := pipelineStem(tc.path); got != tc.want {
			t.Errorf("FAIL: pipelineStem(%q) = %q, want %q — %s", tc.path, got, tc.want, tc.why)
			continue
		}
		t.Logf("ok: %s", tc.why)
	}
}

// A leading dot is a whole name, not an empty stem with an extension.
func TestADotfilePipelineKeepsItsName(t *testing.T) {
	if got := pipelineStem("ci/.hidden"); got != ".hidden" {
		t.Fatalf("FAIL: pipelineStem = %q, want .hidden", got)
	}
	t.Log("ok: a dotfile keeps its name")
}