Skip to content
quarry Artifact [7d165376ee]
Login

Artifact [7d165376ee]

Artifact 7d165376ee3a51ba980b19cac55fc877dc328098ccb42f4d325ce257a5c5ec58:


package ci

import (
	"strings"
	"testing"
)

// The mistake the Runners form invited, and the one it now refuses.
//
// dagnats matches a scope as a whole task type or as a namespace the
// type continues after a dot, so a trailing separator can match
// nothing. The form said "prefixes" and suggested "e2e- build-", which
// is exactly the shape that never matches (bd68d1073409).
func TestUnmatchableScopeCatchesAPrefix(t *testing.T) {
	for _, bad := range []string{"e2e-", "build-", "dantest-", "nightly_"} {
		why := UnmatchableScope(bad)
		if why == "" {
			t.Errorf("FAIL %q was accepted: it matches no task type and fails at poll time", bad)
			continue
		}
		t.Logf("ok %q refused", bad)
	}
	if why := UnmatchableScope("dantest-puzzles."); why == "" {
		t.Error("FAIL a trailing dot was accepted")
	}
}

// A refusal that does not say what to type instead just moves the
// dead end. The whole defect was a message pointing away from the
// cause, so this one has to point at it.
func TestUnmatchableScopeSaysWhatToTypeInstead(t *testing.T) {
	why := UnmatchableScope("dantest-")
	for _, want := range []string{"dantest-puzzles", "dot", "task type"} {
		if !strings.Contains(why, want) {
			t.Errorf("FAIL the refusal never mentions %q: %s", want, why)
		}
	}
	t.Logf("ok: %s", why)
}

// The real thing must pass. A guard that refuses the working case is
// worse than no guard, and this rule is a heuristic over names rather
// than a proof, so the accepted side is the half worth pinning.
func TestUnmatchableScopeAcceptsRealTaskTypes(t *testing.T) {
	for _, good := range []string{
		"dantest-puzzles", // jva's, which produced a green run
		"dantest-html",
		"e2e",         // no trailing separator
		"build.linux", // already a dotted namespace
		"dantest-puzzles.26acbacb9e1879580c89a231477106f4", // a whole run-scoped type
	} {
		if why := UnmatchableScope(good); why != "" {
			t.Errorf("FAIL %q was refused: %s", good, why)
			continue
		}
		t.Logf("ok %q accepted", good)
	}
}