package testci import ( "fmt" "strings" "testing" ) // recorder stands in for a test, so Absent's verdict can be read. type recorder struct { testing.TB skipped, failed string } func (r *recorder) Helper() {} func (r *recorder) Skip(args ...any) { r.skipped = fmt.Sprint(args...) } func (r *recorder) Fatalf(f string, a ...any) { r.failed = fmt.Sprintf(f, a...) } func TestAbsentSkipsOnADeveloperMachine(t *testing.T) { t.Setenv(ToolsRequired, "") r := &recorder{TB: t} Absent(r, "pinned program absent") if r.skipped != "pinned program absent" || r.failed != "" { t.Fatalf("want a skip, got skip %q fail %q", r.skipped, r.failed) } } // Where CI installs the pinned programs, a missing one is a failure: a // skip there would be a green run that tested nothing. func TestAbsentFailsWhereToolsAreRequired(t *testing.T) { t.Setenv(ToolsRequired, "1") r := &recorder{TB: t} Absent(r, "pinned program absent") if r.skipped != "" || !strings.Contains(r.failed, "pinned program absent") || !strings.Contains(r.failed, ToolsRequired) { t.Fatalf("want a failure naming the program and the variable, got skip %q fail %q", r.skipped, r.failed) } }