e2e/ci_nojobs_test.go
51 lines · 1950 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 t.Parallel()
15 inst := startInstance(t)
16 aliceKey := inst.newKey(t, "alice")
17 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub",
18 "--email", "alice@example.test", "--verified")
19
20 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
21 t.Fatalf("repo create: %s", errOut)
22 }
23 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "settings", "require-checks", "alice/app", "on"); code != 0 {
24 t.Fatalf("require-checks on: %s", errOut)
25 }
26
27 work := t.TempDir()
28 env := inst.gitEnv(aliceKey)
29 mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w")
30 dir := filepath.Join(work, "w")
31 os.WriteFile(filepath.Join(dir, "README"), []byte("x\n"), 0o644)
32 mustGit(t, dir, env, "checkout", "-q", "-b", "main")
33 mustGit(t, dir, env, "add", ".")
34 mustGit(t, dir, env, "commit", "-q", "-m", "base")
35 mustGit(t, dir, env, "push", "-q", "origin", "main")
36
37 mustGit(t, dir, env, "checkout", "-q", "-b", "feature")
38 os.WriteFile(filepath.Join(dir, "README"), []byte("y\n"), 0o644)
39 mustGit(t, dir, env, "add", ".")
40 mustGit(t, dir, env, "commit", "-q", "-m", "change")
41 mustGit(t, dir, env, "push", "-q", "origin", "feature")
42
43 if _, errOut, code := inst.ssh(t, aliceKey, "", "mr", "create", "alice/app",
44 "--source", "feature", "--target", "main", "--title", "change"); code != 0 {
45 t.Fatalf("mr create: %s", errOut)
46 }
47 if out, errOut, code := inst.ssh(t, aliceKey, "", "mr", "merge", "alice/app", "1",
48 "--strategy", "merge"); code != 0 {
49 t.Fatalf("mr merge refused under require_checks with no CI: %s %s", out, errOut)
50 }
51}