e2e/ci_skipped_test.go

v1.40.0
gitbay/e2e/ci_skipped_test.go history · blame · raw

71 lines · 2960 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	t.Parallel()
17	inst := startInstance(t)
18	aliceKey := inst.newKey(t, "alice")
19	inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub",
20		"--email", "alice@example.test", "--verified")
21
22	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
23		t.Fatalf("repo create: %s", errOut)
24	}
25	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "settings", "require-checks", "alice/app", "on"); code != 0 {
26		t.Fatalf("require-checks on: %s", errOut)
27	}
28
29	work := t.TempDir()
30	env := inst.gitEnv(aliceKey)
31	mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w")
32	dir := filepath.Join(work, "w")
33	os.MkdirAll(filepath.Join(dir, ".gitbay"), 0o755)
34	os.MkdirAll(filepath.Join(dir, "docs"), 0o755)
35	os.WriteFile(filepath.Join(dir, ".gitbay", "ci.yml"), []byte(
36		"jobs:\n  unit:\n    paths-ignore:\n      - docs/**\n    steps:\n      - echo hi\n"), 0o644)
37	os.WriteFile(filepath.Join(dir, "docs", "x.md"), []byte("# x\n"), 0o644)
38	mustGit(t, dir, env, "checkout", "-q", "-b", "main")
39	mustGit(t, dir, env, "add", ".")
40	mustGit(t, dir, env, "commit", "-q", "-m", "base")
41	mustGit(t, dir, env, "push", "-q", "origin", "main")
42
43	// A docs-only feature branch: the job's paths-ignore excludes every
44	// file this push touches.
45	mustGit(t, dir, env, "checkout", "-q", "-b", "docs-fix")
46	os.WriteFile(filepath.Join(dir, "docs", "x.md"), []byte("# x, fixed\n"), 0o644)
47	mustGit(t, dir, env, "add", ".")
48	mustGit(t, dir, env, "commit", "-q", "-m", "fix a typo")
49	mustGit(t, dir, env, "push", "-q", "origin", "docs-fix")
50	headSHA := strings.TrimSpace(mustGit(t, dir, env, "rev-parse", "HEAD"))
51
52	status, _, code := inst.ssh(t, aliceKey, "", "status", "list", "alice/app", headSHA)
53	if code != 0 {
54		t.Fatalf("status list: %s", status)
55	}
56	if !strings.Contains(status, "ci/unit") || !strings.Contains(status, "skipped") {
57		t.Fatalf("no skipped ci/unit status on %s:\n%s", headSHA, status)
58	}
59
60	if _, errOut, code := inst.ssh(t, aliceKey, "", "mr", "create", "alice/app",
61		"--source", "docs-fix", "--target", "main", "--title", "'fix a typo'"); code != 0 {
62		t.Fatalf("mr create: %s", errOut)
63	}
64
65	// Before #172 this failed with "requires green checks and none were
66	// reported": the filtered push left the head with no statuses at all.
67	if out, errOut, code := inst.ssh(t, aliceKey, "", "mr", "merge", "alice/app", "1",
68		"--strategy", "merge"); code != 0 {
69		t.Fatalf("mr merge refused a docs-only change under require_checks: %s %s", out, errOut)
70	}
71}