e2e/ci_nojobs_test.go
50 lines · 1936 bytes
1package e2e
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9// require_checks on a repository with no CI configuration used to refuse
10// every merge with "none were reported", and the only way out was turning
11// the setting off. Nothing was ever going to report, so the gate has
12// nothing to wait for.
13func TestRequireChecksWithoutCIConfigMerges(t *testing.T) {
14 inst := startInstance(t)
15 aliceKey := inst.newKey(t, "alice")
16 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub",
17 "--email", "alice@example.test", "--verified")
18
19 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
20 t.Fatalf("repo create: %s", errOut)
21 }
22 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "settings", "require-checks", "alice/app", "on"); code != 0 {
23 t.Fatalf("require-checks on: %s", errOut)
24 }
25
26 work := t.TempDir()
27 env := inst.gitEnv(aliceKey)
28 mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w")
29 dir := filepath.Join(work, "w")
30 os.WriteFile(filepath.Join(dir, "README"), []byte("x\n"), 0o644)
31 mustGit(t, dir, env, "checkout", "-q", "-b", "main")
32 mustGit(t, dir, env, "add", ".")
33 mustGit(t, dir, env, "commit", "-q", "-m", "base")
34 mustGit(t, dir, env, "push", "-q", "origin", "main")
35
36 mustGit(t, dir, env, "checkout", "-q", "-b", "feature")
37 os.WriteFile(filepath.Join(dir, "README"), []byte("y\n"), 0o644)
38 mustGit(t, dir, env, "add", ".")
39 mustGit(t, dir, env, "commit", "-q", "-m", "change")
40 mustGit(t, dir, env, "push", "-q", "origin", "feature")
41
42 if _, errOut, code := inst.ssh(t, aliceKey, "", "mr", "create", "alice/app",
43 "--source", "feature", "--target", "main", "--title", "change"); code != 0 {
44 t.Fatalf("mr create: %s", errOut)
45 }
46 if out, errOut, code := inst.ssh(t, aliceKey, "", "mr", "merge", "alice/app", "1",
47 "--strategy", "merge"); code != 0 {
48 t.Fatalf("mr merge refused under require_checks with no CI: %s %s", out, errOut)
49 }
50}