| @@ -0,0 +1,113 @@ |
| |
1 | package e2e |
| |
2 | |
| |
3 | import ( |
| |
4 | "net/http" |
| |
5 | "net/url" |
| |
6 | "os" |
| |
7 | "os/exec" |
| |
8 | "path/filepath" |
| |
9 | "strings" |
| |
10 | "sync" |
| |
11 | "testing" |
| |
12 | ) |
| |
13 | |
| |
14 | // Paths and content outside ASCII go through every read surface: the |
| |
15 | // tree, cat, grep, blame and the web blob page. Nothing in the suite |
| |
16 | // covered a non-ASCII path before (#129). |
| |
17 | func TestNonASCIIPaths(t *testing.T) { |
| |
18 | inst := startInstance(t) |
| |
19 | aliceKey := inst.newKey(t, "alice") |
| |
20 | inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub") |
| |
21 | if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 { |
| |
22 | t.Fatalf("repo create: %s", errOut) |
| |
23 | } |
| |
24 | work := t.TempDir() |
| |
25 | env := inst.gitEnv(aliceKey) |
| |
26 | mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w") |
| |
27 | dir := filepath.Join(work, "w") |
| |
28 | const name = "dokumente/übersicht — ünïcode.txt" |
| |
29 | os.MkdirAll(filepath.Join(dir, "dokumente"), 0o755) |
| |
30 | os.WriteFile(filepath.Join(dir, name), []byte("Grüße aus Nürnberg\n日本語の行\n"), 0o644) |
| |
31 | mustGit(t, dir, env, "-c", "core.quotepath=off", "checkout", "-q", "-b", "main") |
| |
32 | mustGit(t, dir, env, "add", ".") |
| |
33 | mustGit(t, dir, env, "commit", "-q", "-m", "ünïcode") |
| |
34 | mustGit(t, dir, env, "push", "-q", "origin", "main") |
| |
35 | |
| |
36 | if out, errOut, code := inst.ssh(t, aliceKey, "", "repo", "tree", "alice/app", "dokumente", "--json"); code != 0 || !strings.Contains(out, "übersicht") { |
| |
37 | t.Fatalf("repo tree: exit %d\n%s%s", code, out, errOut) |
| |
38 | } |
| |
39 | // inst.ssh joins arguments into one command line; the name has spaces. |
| |
40 | quoted := "'" + name + "'" |
| |
41 | if out, errOut, code := inst.ssh(t, aliceKey, "", "repo", "cat", "alice/app", quoted); code != 0 || !strings.Contains(out, "Nürnberg") { |
| |
42 | t.Fatalf("repo cat: exit %d\n%s%s", code, out, errOut) |
| |
43 | } |
| |
44 | if out, errOut, code := inst.ssh(t, aliceKey, "", "repo", "grep", "alice/app", "日本語"); code != 0 || !strings.Contains(out, "übersicht") { |
| |
45 | t.Fatalf("repo grep: exit %d\n%s%s", code, out, errOut) |
| |
46 | } |
| |
47 | if out, errOut, code := inst.ssh(t, aliceKey, "", "repo", "blame", "alice/app", quoted); code != 0 || !strings.Contains(out, "Nürnberg") { |
| |
48 | t.Fatalf("repo blame: exit %d\n%s%s", code, out, errOut) |
| |
49 | } |
| |
50 | page := inst.base() + "/alice/app/blob/main/" + url.PathEscape("dokumente") + "/" + url.PathEscape("übersicht — ünïcode.txt") |
| |
51 | resp, err := http.Get(page) |
| |
52 | if err != nil { |
| |
53 | t.Fatal(err) |
| |
54 | } |
| |
55 | defer resp.Body.Close() |
| |
56 | if resp.StatusCode != 200 { |
| |
57 | t.Fatalf("web blob page: %d", resp.StatusCode) |
| |
58 | } |
| |
59 | } |
| |
60 | |
| |
61 | // Pushes to different branches of one repository at the same time all |
| |
62 | // land: the receive hooks, the post-receive work and the store take |
| |
63 | // them concurrently without losing one (#129). |
| |
64 | func TestConcurrentPushes(t *testing.T) { |
| |
65 | inst := startInstance(t) |
| |
66 | aliceKey := inst.newKey(t, "alice") |
| |
67 | inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub") |
| |
68 | if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 { |
| |
69 | t.Fatalf("repo create: %s", errOut) |
| |
70 | } |
| |
71 | env := inst.gitEnv(aliceKey) |
| |
72 | seed := filepath.Join(t.TempDir(), "seed") |
| |
73 | mustGit(t, t.TempDir(), env, "clone", inst.sshURL("alice/app"), seed) |
| |
74 | os.WriteFile(filepath.Join(seed, "f.txt"), []byte("x\n"), 0o644) |
| |
75 | mustGit(t, seed, env, "checkout", "-q", "-b", "main") |
| |
76 | mustGit(t, seed, env, "add", ".") |
| |
77 | mustGit(t, seed, env, "commit", "-q", "-m", "base") |
| |
78 | mustGit(t, seed, env, "push", "-q", "origin", "main") |
| |
79 | |
| |
80 | const n = 6 |
| |
81 | var wg sync.WaitGroup |
| |
82 | errs := make([]string, n) |
| |
83 | for i := 0; i < n; i++ { |
| |
84 | branch := "b" + string(rune('0'+i)) |
| |
85 | clone := filepath.Join(t.TempDir(), branch) |
| |
86 | mustGit(t, t.TempDir(), env, "clone", "-q", inst.sshURL("alice/app"), clone) |
| |
87 | mustGit(t, clone, env, "checkout", "-q", "-b", branch) |
| |
88 | os.WriteFile(filepath.Join(clone, branch+".txt"), []byte(branch+"\n"), 0o644) |
| |
89 | mustGit(t, clone, env, "add", ".") |
| |
90 | mustGit(t, clone, env, "commit", "-q", "-m", branch) |
| |
91 | wg.Add(1) |
| |
92 | go func(i int, clone, branch string) { |
| |
93 | defer wg.Done() |
| |
94 | cmd := exec.Command("git", "push", "-q", "origin", branch) |
| |
95 | cmd.Dir, cmd.Env = clone, env |
| |
96 | if out, err := cmd.CombinedOutput(); err != nil { |
| |
97 | errs[i] = string(out) |
| |
98 | } |
| |
99 | }(i, clone, branch) |
| |
100 | } |
| |
101 | wg.Wait() |
| |
102 | for i, e := range errs { |
| |
103 | if e != "" { |
| |
104 | t.Errorf("push %d failed:\n%s", i, e) |
| |
105 | } |
| |
106 | } |
| |
107 | out, _, _ := inst.ssh(t, aliceKey, "", "repo", "refs", "alice/app") |
| |
108 | for i := 0; i < n; i++ { |
| |
109 | if !strings.Contains(out, "b"+string(rune('0'+i))) { |
| |
110 | t.Errorf("branch b%d missing after concurrent pushes:\n%s", i, out) |
| |
111 | } |
| |
112 | } |
| |
113 | } |