Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Code

392 commit(s) on main

Merge change request 01M70WES5ZZDJ6RP226WB11BBZ: Let people rename and remove their own passkeys keenan · 2h ago 4b8c9e1d
history blame raw 2.9 KiB
1package index
2
3import (
4 "os/exec"
5 "testing"
6
7 "rodent.software/vole/core/git"
8)
9
10func TestRefreshHeadStoresRecentCommitsAndLanguages(t *testing.T) {
11 t.Parallel()
12 s, m, g := incrementalRepo(t)
13 m.DefaultBranch = "main"
14 first := seedHead(t, g, map[string][]byte{"main.go": []byte("package main\n")})
15 second, err := git.CommitFiles(g, "refs/heads/main", func(f map[string][]byte) error {
16 f["main.go"] = []byte("package main\n\nfunc main() {}\n")
17 f["README.md"] = []byte("# demo\n")
18 return nil
19 }, "the second commit", "ada")
20 if err != nil {
21 t.Fatal(err)
22 }
23 changed, err := s.RefreshHead(m)
24 if err != nil {
25 t.Fatal(err)
26 }
27 if !changed {
28 t.Fatal("the first refresh reported no change")
29 }
30 commits, err := s.RecentCommits(m.ID, 5)
31 if err != nil {
32 t.Fatal(err)
33 }
34 if len(commits) != 2 || commits[0].SHA != second || commits[1].SHA != first {
35 t.Fatalf("recent commits = %+v, want %s then %s", commits, second, first)
36 }
37 if commits[0].Subject != "the second commit" || commits[0].Author != "ada" {
38 t.Fatalf("tip commit = %+v", commits[0])
39 }
40 languages, err := s.Languages(m.ID)
41 if err != nil {
42 t.Fatal(err)
43 }
44 byName := map[string]int64{}
45 for _, l := range languages {
46 byName[l.Name] = l.Bytes
47 }
48 if byName["Go"] == 0 || byName["Markdown"] == 0 {
49 t.Fatalf("languages = %+v, want Go and Markdown", languages)
50 }
51 changed, err = s.RefreshHead(m)
52 if err != nil {
53 t.Fatal(err)
54 }
55 if changed {
56 t.Fatal("a second refresh at the same tip reported a change")
57 }
58}
59
60func TestRefreshTagsStoresTagsAndReleaseEvents(t *testing.T) {
61 t.Parallel()
62 s, m, g := incrementalRepo(t)
63 m.DefaultBranch = "main"
64 commit := seedHead(t, g, map[string][]byte{"main.go": []byte("package main\n")})
65 if err := g.WriteAnnotatedTag("v1.0.0", commit, "first release", "keenan", false); err != nil {
66 t.Fatal(err)
67 }
68 cmd := exec.Command("git", "-C", g.Dir, "tag", "light", commit)
69 cmd.Env = append(cmd.Environ(), "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@example.com")
70 if out, err := cmd.CombinedOutput(); err != nil {
71 t.Fatalf("lightweight tag: %v: %s", err, out)
72 }
73 if err := s.RefreshTags(m); err != nil {
74 t.Fatal(err)
75 }
76 tags, err := s.Tags(m.ID, 5)
77 if err != nil {
78 t.Fatal(err)
79 }
80 if len(tags) != 2 {
81 t.Fatalf("tags = %+v, want two", tags)
82 }
83 byName := map[string]TagRow{}
84 for _, tag := range tags {
85 byName[tag.Name] = tag
86 }
87 if !byName["v1.0.0"].Annotated || byName["v1.0.0"].Commit != commit || byName["v1.0.0"].Tagger != "keenan" {
88 t.Fatalf("annotated tag = %+v", byName["v1.0.0"])
89 }
90 if byName["light"].Annotated || byName["light"].Commit != commit {
91 t.Fatalf("lightweight tag = %+v", byName["light"])
92 }
93 if err := g.DeleteRef("refs/tags/v1.0.0"); err != nil {
94 t.Fatal(err)
95 }
96 if err := s.RefreshTags(m); err != nil {
97 t.Fatal(err)
98 }
99 tags, err = s.Tags(m.ID, 5)
100 if err != nil {
101 t.Fatal(err)
102 }
103 if len(tags) != 1 || tags[0].Name != "light" {
104 t.Fatalf("after deleting a tag: %+v", tags)
105 }
106}
107