e2e/ci_skipped_test.go

e9566eed86ebcd185c4b85f63d667b5e671fe787
gitbay/e2e/ci_skipped_test.go history · blame · raw

70 lines · 2946 bytes

 1package e2e
 2
 3import (
 4	"os"
 5	"path/filepath"
 6	"strings"
 7	"testing"
 8)
 9
10// A repository with require_checks on and a job whose paths-ignore excludes
11// a docs-only change used to be unmergeable: the push queued nothing, so the
12// head carried no statuses at all, and the gate refuses that outright. The
13// filtered job now records a "skipped" status instead, which the gate reads
14// as green (#172).
15func TestSkippedStatusSatisfiesRequireChecks(t *testing.T) {
16	inst := startInstance(t)
17	aliceKey := inst.newKey(t, "alice")
18	inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub",
19		"--email", "alice@example.test", "--verified")
20
21	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
22		t.Fatalf("repo create: %s", errOut)
23	}
24	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "settings", "require-checks", "alice/app", "on"); code != 0 {
25		t.Fatalf("require-checks on: %s", errOut)
26	}
27
28	work := t.TempDir()
29	env := inst.gitEnv(aliceKey)
30	mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w")
31	dir := filepath.Join(work, "w")
32	os.MkdirAll(filepath.Join(dir, ".gitbay"), 0o755)
33	os.MkdirAll(filepath.Join(dir, "docs"), 0o755)
34	os.WriteFile(filepath.Join(dir, ".gitbay", "ci.yml"), []byte(
35		"jobs:\n  unit:\n    paths-ignore:\n      - docs/**\n    steps:\n      - echo hi\n"), 0o644)
36	os.WriteFile(filepath.Join(dir, "docs", "x.md"), []byte("# x\n"), 0o644)
37	mustGit(t, dir, env, "checkout", "-q", "-b", "main")
38	mustGit(t, dir, env, "add", ".")
39	mustGit(t, dir, env, "commit", "-q", "-m", "base")
40	mustGit(t, dir, env, "push", "-q", "origin", "main")
41
42	// A docs-only feature branch: the job's paths-ignore excludes every
43	// file this push touches.
44	mustGit(t, dir, env, "checkout", "-q", "-b", "docs-fix")
45	os.WriteFile(filepath.Join(dir, "docs", "x.md"), []byte("# x, fixed\n"), 0o644)
46	mustGit(t, dir, env, "add", ".")
47	mustGit(t, dir, env, "commit", "-q", "-m", "fix a typo")
48	mustGit(t, dir, env, "push", "-q", "origin", "docs-fix")
49	headSHA := strings.TrimSpace(mustGit(t, dir, env, "rev-parse", "HEAD"))
50
51	status, _, code := inst.ssh(t, aliceKey, "", "status", "list", "alice/app", headSHA)
52	if code != 0 {
53		t.Fatalf("status list: %s", status)
54	}
55	if !strings.Contains(status, "ci/unit") || !strings.Contains(status, "skipped") {
56		t.Fatalf("no skipped ci/unit status on %s:\n%s", headSHA, status)
57	}
58
59	if _, errOut, code := inst.ssh(t, aliceKey, "", "mr", "create", "alice/app",
60		"--source", "docs-fix", "--target", "main", "--title", "'fix a typo'"); code != 0 {
61		t.Fatalf("mr create: %s", errOut)
62	}
63
64	// Before #172 this failed with "requires green checks and none were
65	// reported": the filtered push left the head with no statuses at all.
66	if out, errOut, code := inst.ssh(t, aliceKey, "", "mr", "merge", "alice/app", "1",
67		"--strategy", "merge"); code != 0 {
68		t.Fatalf("mr merge refused a docs-only change under require_checks: %s %s", out, errOut)
69	}
70}