krz/gitbay
A CLI-first git forge.
clone: git clone https://gitbay.org/krz/gitbay.git
main: e2e/description_test.go · raw
1package e2e
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestRepoDescriptions(t *testing.T) {
9 inst := startInstance(t)
10 aliceKey := inst.newKey(t, "alice")
11 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
12
13 // Set at creation; visible in show and list (human and JSON).
14 if _, errOut, code := inst.ssh(t, aliceKey, "",
15 "repo", "create", "alice/tool", "--description", "'a fine tool'"); code != 0 {
16 t.Fatalf("create: %s", errOut)
17 }
18 out, _, _ := inst.ssh(t, aliceKey, "", "repo", "show", "alice/tool", "--json")
19 if !strings.Contains(out, `"description":"a fine tool"`) {
20 t.Fatalf("show json: %s", out)
21 }
22 out, _, _ = inst.ssh(t, aliceKey, "", "repo", "list")
23 if !strings.Contains(out, "a fine tool") {
24 t.Fatalf("list: %s", out)
25 }
26
27 // The description lives in the bare repo's native description file.
28 sshOut, _, _ := inst.ssh(t, aliceKey, "", "repo", "show", "alice/tool")
29 if !strings.Contains(sshOut, "a fine tool") {
30 t.Fatalf("show human: %s", sshOut)
31 }
32
33 // Update via settings; first line only, trimmed.
34 if _, errOut, code := inst.ssh(t, aliceKey, "",
35 "repo", "settings", "description", "alice/tool", "'better now'"); code != 0 {
36 t.Fatalf("settings description: %s", errOut)
37 }
38 out, _, _ = inst.ssh(t, aliceKey, "", "repo", "show", "alice/tool", "--json")
39 if !strings.Contains(out, `"description":"better now"`) {
40 t.Fatalf("updated show: %s", out)
41 }
42
43 // Non-admins cannot set it.
44 bobKey := inst.newKey(t, "bob")
45 inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
46 if _, _, code := inst.ssh(t, bobKey, "", "repo", "settings", "description", "alice/tool", "hax"); code != 4 {
47 t.Fatalf("non-admin set: exit %d, want 4", code)
48 }
49
50 // Web: index, owner page, and repo header all show it.
51 for _, path := range []string{"/", "/alice", "/alice/tool"} {
52 status, body := inst.get(t, path)
53 if status != 200 || !strings.Contains(body, "better now") {
54 t.Fatalf("description missing at %s (%d)", path, status)
55 }
56 }
57
58 // Forks inherit the description.
59 if _, errOut, code := inst.ssh(t, bobKey, "", "repo", "fork", "alice/tool"); code != 0 {
60 t.Fatalf("fork: %s", errOut)
61 }
62 out, _, _ = inst.ssh(t, bobKey, "", "repo", "show", "bob/tool", "--json")
63 if !strings.Contains(out, `"description":"better now"`) {
64 t.Fatalf("fork description: %s", out)
65 }
66
67 // A repo with no description set stays clean (git's placeholder is
68 // treated as empty).
69 if _, _, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/plain"); code != 0 {
70 t.Fatal("plain create failed")
71 }
72 out, _, _ = inst.ssh(t, aliceKey, "", "repo", "show", "alice/plain", "--json")
73 if strings.Contains(out, "Unnamed repository") || strings.Contains(out, `"description"`) {
74 t.Fatalf("placeholder leaked: %s", out)
75 }
76}