File view with blame information shown in the left gutter beside each line.

barerepo / server / e2e/oldname_test.go
65 lines · 2.3kb · 133728eaa05486504991b230f9d4c7e986b7defc
log files threads runs releases config jump to file t
133728e barerepo 1mo
1
package e2e
133728e barerepo 1mo
2
133728e barerepo 1mo
3
import (
133728e barerepo 1mo
4
"net/http"
133728e barerepo 1mo
5
"net/url"
133728e barerepo 1mo
6
"os/exec"
133728e barerepo 1mo
7
"strings"
133728e barerepo 1mo
8
"testing"
133728e barerepo 1mo
9
)
133728e barerepo 1mo
10
133728e barerepo 1mo
11
// Chapter 21.2: the old name is never freed, or it inherits the old identity's threads and mentions.
133728e barerepo 1mo
12
func TestARenamedRepositoryNeverFreesItsOldName(t *testing.T) {
133728e barerepo 1mo
13
if _, err := exec.LookPath("git"); err != nil {
133728e barerepo 1mo
14
t.Skip("git is not installed")
133728e barerepo 1mo
15
}
133728e barerepo 1mo
16
in := newInstance(t)
133728e barerepo 1mo
17
john := in.account("john")
133728e barerepo 1mo
18
seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
19
133728e barerepo 1mo
20
resp := post(t, in, "john", "/john/johnbot/rename", url.Values{"name": {"ircbot"}})
133728e barerepo 1mo
21
if resp.StatusCode != http.StatusFound {
133728e barerepo 1mo
22
t.Fatalf("the rename answered %d", resp.StatusCode)
133728e barerepo 1mo
23
}
133728e barerepo 1mo
24
// The old path redirects, which is what keeps every clone working. 44.2.
133728e barerepo 1mo
25
code, _, _ := get(t, in.http.URL+"/john/johnbot")
133728e barerepo 1mo
26
if code != http.StatusOK {
133728e barerepo 1mo
27
t.Errorf("the old path answered %d instead of following the redirect", code)
133728e barerepo 1mo
28
}
133728e barerepo 1mo
29
133728e barerepo 1mo
30
// The form must not hand the old name to anybody, including the person who moved it.
133728e barerepo 1mo
31
resp = post(t, in, "john", "/new", url.Values{"name": {"johnbot"}, "default_branch": {"master"}})
133728e barerepo 1mo
32
if resp.StatusCode == http.StatusFound {
133728e barerepo 1mo
33
t.Error("the form gave the old name back out, so the redirect now lies")
133728e barerepo 1mo
34
}
133728e barerepo 1mo
35
133728e barerepo 1mo
36
// Nor may a push take it, which is the other way a repository comes into being. Chapter 11.
133728e barerepo 1mo
37
work := t.TempDir()
133728e barerepo 1mo
38
run(t, work, "git", "init", "-q", "-b", "master", work)
133728e barerepo 1mo
39
write(t, work, "f", "hi\n")
133728e barerepo 1mo
40
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
41
run(t, work, "git", "commit", "-qm", "first")
133728e barerepo 1mo
42
out, err := try(t, work, "git", "push", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
43
if err == nil && !strings.Contains(out, "ircbot") {
133728e barerepo 1mo
44
t.Errorf("a push claimed the old name instead of following the redirect:\n%s", out)
133728e barerepo 1mo
45
}
133728e barerepo 1mo
46
}
133728e barerepo 1mo
47
133728e barerepo 1mo
48
// Chapter 44.4: a deleted repository keeps its name claimed while it waits out its window.
133728e barerepo 1mo
49
func TestADeletedNameIsNotHandedOutWhileItWaits(t *testing.T) {
133728e barerepo 1mo
50
if _, err := exec.LookPath("git"); err != nil {
133728e barerepo 1mo
51
t.Skip("git is not installed")
133728e barerepo 1mo
52
}
133728e barerepo 1mo
53
in := newInstance(t)
133728e barerepo 1mo
54
john := in.account("john")
133728e barerepo 1mo
55
seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
56
133728e barerepo 1mo
57
resp := post(t, in, "john", "/john/johnbot/delete", url.Values{"confirm": {"johnbot"}})
133728e barerepo 1mo
58
if resp.StatusCode != http.StatusFound {
133728e barerepo 1mo
59
t.Fatalf("the delete answered %d", resp.StatusCode)
133728e barerepo 1mo
60
}
133728e barerepo 1mo
61
resp = post(t, in, "john", "/new", url.Values{"name": {"johnbot"}, "default_branch": {"master"}})
133728e barerepo 1mo
62
if resp.StatusCode == http.StatusFound {
133728e barerepo 1mo
63
t.Error("a name still in the trash window was handed straight back out")
133728e barerepo 1mo
64
}
133728e barerepo 1mo
65
}
history · rawbarerepo 0.1.0