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

barerepo / server / e2e/history_test.go
79 lines · 3.0kb · 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
"os/exec"
133728e barerepo 1mo
6
"strings"
133728e barerepo 1mo
7
"testing"
133728e barerepo 1mo
8
)
133728e barerepo 1mo
9
133728e barerepo 1mo
10
// Chapter 24 gives the file view a history link and the config page history, blame and raw.
133728e barerepo 1mo
11
func TestOneFileHasItsOwnHistory(t *testing.T) {
133728e barerepo 1mo
12
if _, err := exec.LookPath("git"); err != nil {
133728e barerepo 1mo
13
t.Skip("git is not installed")
133728e barerepo 1mo
14
}
133728e barerepo 1mo
15
in := newInstance(t)
133728e barerepo 1mo
16
john := in.account("john")
133728e barerepo 1mo
17
work := seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
18
133728e barerepo 1mo
19
write(t, work, "conn.go", "package irc\n\nfunc dial() error { return nil }\n")
133728e barerepo 1mo
20
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
21
run(t, work, "git", "commit", "-qm", "add the dialer")
133728e barerepo 1mo
22
write(t, work, "other.go", "package irc\n\nfunc unrelated() {}\n")
133728e barerepo 1mo
23
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
24
run(t, work, "git", "commit", "-qm", "a commit that never touches the dialer")
133728e barerepo 1mo
25
write(t, work, "conn.go", "package irc\n\nfunc dial() error { return errBusy }\n")
133728e barerepo 1mo
26
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
27
run(t, work, "git", "commit", "-qm", "the dialer returns busy now")
133728e barerepo 1mo
28
run(t, work, "git", "push", "-q", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
29
133728e barerepo 1mo
30
// The file view's history link is the only way to ask this question from a page.
133728e barerepo 1mo
31
code, _, file := get(t, in.http.URL+"/john/johnbot/file/master/conn.go")
133728e barerepo 1mo
32
if code != http.StatusOK {
133728e barerepo 1mo
33
t.Fatalf("the file view answered %d", code)
133728e barerepo 1mo
34
}
133728e barerepo 1mo
35
if !strings.Contains(file, `href="/john/johnbot?path=conn.go"`) {
133728e barerepo 1mo
36
t.Errorf("the file view does not link to its own history:\n%s", footOf(file))
133728e barerepo 1mo
37
}
133728e barerepo 1mo
38
133728e barerepo 1mo
39
code, _, hist := get(t, in.http.URL+"/john/johnbot?path=conn.go")
133728e barerepo 1mo
40
if code != http.StatusOK {
133728e barerepo 1mo
41
t.Fatalf("the history answered %d", code)
133728e barerepo 1mo
42
}
133728e barerepo 1mo
43
for _, want := range []string{"add the dialer", "the dialer returns busy now"} {
133728e barerepo 1mo
44
if !strings.Contains(hist, want) {
133728e barerepo 1mo
45
t.Errorf("the history of conn.go lost %q", want)
133728e barerepo 1mo
46
}
133728e barerepo 1mo
47
}
133728e barerepo 1mo
48
// A commit that never touched the file is the whole point of asking for one file.
133728e barerepo 1mo
49
if strings.Contains(hist, "a commit that never touches the dialer") {
133728e barerepo 1mo
50
t.Error("the history of conn.go carries a commit that does not touch conn.go")
133728e barerepo 1mo
51
}
133728e barerepo 1mo
52
// Every row counts only this file, since that is what asking for one file means.
133728e barerepo 1mo
53
if !strings.Contains(hist, "conn.go · +1 -1") {
133728e barerepo 1mo
54
t.Errorf("a row does not count conn.go alone:\n%s", hist)
133728e barerepo 1mo
55
}
133728e barerepo 1mo
56
// And it says what it is restricted to, or a reader cannot tell it from the whole log.
133728e barerepo 1mo
57
if !strings.Contains(hist, "history of") || !strings.Contains(hist, "the whole log") {
133728e barerepo 1mo
58
t.Error("the history page does not say it is one file, nor offer the way back")
133728e barerepo 1mo
59
}
133728e barerepo 1mo
60
133728e barerepo 1mo
61
// The config page is a file view with a fixed path, so chapter 24 gives it all three links.
133728e barerepo 1mo
62
code, _, cfg := get(t, in.http.URL+"/john/johnbot/config")
133728e barerepo 1mo
63
if code != http.StatusOK {
133728e barerepo 1mo
64
t.Fatalf("the config page answered %d", code)
133728e barerepo 1mo
65
}
133728e barerepo 1mo
66
for _, want := range []string{">history</a>", ">blame</a>", ">raw</a>"} {
133728e barerepo 1mo
67
if !strings.Contains(cfg, want) {
133728e barerepo 1mo
68
t.Errorf("the config page is missing its %s link", strings.Trim(want, ">/a<"))
133728e barerepo 1mo
69
}
133728e barerepo 1mo
70
}
133728e barerepo 1mo
71
}
133728e barerepo 1mo
72
133728e barerepo 1mo
73
// footOf is the last of a page, which is where every one of these links lives.
133728e barerepo 1mo
74
func footOf(body string) string {
133728e barerepo 1mo
75
if i := strings.LastIndex(body, `class="foot"`); i >= 0 {
133728e barerepo 1mo
76
return body[i:]
133728e barerepo 1mo
77
}
133728e barerepo 1mo
78
return body
133728e barerepo 1mo
79
}
history · rawbarerepo 0.1.0