e2e/mergerecord_test.go

v1.41.0
gitbay/e2e/mergerecord_test.go history · blame · raw

50 lines · 2176 bytes

 1package e2e
 2
 3import (
 4	"os"
 5	"path/filepath"
 6	"strings"
 7	"testing"
 8)
 9
10// A merge request whose head the target already contains is recorded as
11// merged rather than refused: the branch was merged by hand and pushed,
12// or a merge moved the ref and then failed to record itself. Either way
13// refusing left the merge request open for good (#108).
14func TestMergeRecordedWhenTargetContainsHead(t *testing.T) {
15	t.Parallel()
16	inst := startInstance(t)
17	aliceKey := inst.newKey(t, "alice")
18	inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
19	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
20		t.Fatalf("repo create: %s", errOut)
21	}
22	work := t.TempDir()
23	env := inst.gitEnv(aliceKey)
24	mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w")
25	dir := filepath.Join(work, "w")
26	os.WriteFile(filepath.Join(dir, "f.txt"), []byte("x\n"), 0o644)
27	mustGit(t, dir, env, "checkout", "-q", "-b", "main")
28	mustGit(t, dir, env, "add", ".")
29	mustGit(t, dir, env, "commit", "-q", "-m", "base")
30	mustGit(t, dir, env, "push", "-q", "origin", "main")
31	mustGit(t, dir, env, "checkout", "-q", "-b", "feat")
32	os.WriteFile(filepath.Join(dir, "f.txt"), []byte("y\n"), 0o644)
33	mustGit(t, dir, env, "add", ".")
34	mustGit(t, dir, env, "commit", "-q", "-m", "change")
35	mustGit(t, dir, env, "push", "-q", "origin", "feat")
36	if _, errOut, code := inst.ssh(t, aliceKey, "", "mr", "create", "alice/app", "--source", "feat", "--target", "main", "--title", "change"); code != 0 {
37		t.Fatalf("mr create: %s", errOut)
38	}
39	// Merged by hand: main fast-forwards to the branch outside the forge.
40	mustGit(t, dir, env, "push", "-q", "origin", "feat:main")
41
42	out, errOut, code := inst.ssh(t, aliceKey, "", "mr", "merge", "alice/app", "1", "--json")
43	if code != 0 || !strings.Contains(out, `"strategy":"recorded"`) {
44		t.Fatalf("merge of an already-landed head: exit %d\n%s%s", code, out, errOut)
45	}
46	show, _, _ := inst.ssh(t, aliceKey, "", "mr", "show", "alice/app", "1", "--json")
47	if !strings.Contains(show, `"state":"merged"`) || !strings.Contains(show, `"merged_by":"alice"`) {
48		t.Fatalf("merge request not recorded as merged:\n%s", show)
49	}
50}