oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package testci
2
3import (
4 "fmt"
5 "strings"
6 "testing"
7)
8
9// recorder stands in for a test, so Absent's verdict can be read.
10type recorder struct {
11 testing.TB
12 skipped, failed string
13}
14
15func (r *recorder) Helper() {}
16func (r *recorder) Skip(args ...any) { r.skipped = fmt.Sprint(args...) }
17func (r *recorder) Fatalf(f string, a ...any) { r.failed = fmt.Sprintf(f, a...) }
18
19func 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.
30func 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