Download this file
| 1 | package testci |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // recorder stands in for a test, so Absent's verdict can be read. |
| 10 | type recorder struct { |
| 11 | testing.TB |
| 12 | skipped, failed string |
| 13 | } |
| 14 | |
| 15 | func (r *recorder) Helper() {} |
| 16 | func (r *recorder) Skip(args ...any) { r.skipped = fmt.Sprint(args...) } |
| 17 | func (r *recorder) Fatalf(f string, a ...any) { r.failed = fmt.Sprintf(f, a...) } |
| 18 | |
| 19 | func TestAbsentSkipsOnADeveloperMachine(t *testing.T) { |
| 20 | t.Setenv(ToolsRequired, "") |
| 21 | r := &recorder{TB: t} |
| 22 | Absent(r, "pinned program absent") |
| 23 | if r.skipped != "pinned program absent" || r.failed != "" { |
| 24 | t.Fatalf("want a skip, got skip %q fail %q", r.skipped, r.failed) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // Where CI installs the pinned programs, a missing one is a failure: a |
| 29 | // skip there would be a green run that tested nothing. |
| 30 | func TestAbsentFailsWhereToolsAreRequired(t *testing.T) { |
| 31 | t.Setenv(ToolsRequired, "1") |
| 32 | r := &recorder{TB: t} |
| 33 | Absent(r, "pinned program absent") |
| 34 | if r.skipped != "" || !strings.Contains(r.failed, "pinned program absent") || !strings.Contains(r.failed, ToolsRequired) { |
| 35 | t.Fatalf("want a failure naming the program and the variable, got skip %q fail %q", r.skipped, r.failed) |
| 36 | } |
| 37 | } |
| 38 | |