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

barerepo / server / e2e/fileview_test.go
63 lines · 2.1kb · master
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 42.4: binary content is not rendered, and a file over a megabyte is not either.
133728e barerepo 1mo
11
func TestTheFileViewRefusesToRenderWhatItShouldNot(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, "logo.bin", "\x00\x01\x02binary\x00bytes\n")
133728e barerepo 1mo
20
write(t, work, "huge.txt", strings.Repeat("a line of a very large file\n", 40000))
133728e barerepo 1mo
21
write(t, work, "small.txt", "one line\n")
133728e barerepo 1mo
22
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
23
run(t, work, "git", "commit", "-qm", "add the awkward ones")
133728e barerepo 1mo
24
run(t, work, "git", "push", "-q", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
25
133728e barerepo 1mo
26
cases := []struct {
133728e barerepo 1mo
27
path string
133728e barerepo 1mo
28
want []string
133728e barerepo 1mo
29
not []string
133728e barerepo 1mo
30
}{
133728e barerepo 1mo
31
// A null byte in the first 8000 marks it binary, and the page offers the bytes instead.
133728e barerepo 1mo
32
{"/john/johnbot/file/master/logo.bin",
133728e barerepo 1mo
33
[]string{"binary file", "download"}, []string{"binary\x00bytes"}},
133728e barerepo 1mo
34
// Over a megabyte the page says so rather than sending it, per the same section.
133728e barerepo 1mo
35
{"/john/johnbot/file/master/huge.txt",
133728e barerepo 1mo
36
[]string{"too large to render", "download"}, []string{"a line of a very large file"}},
133728e barerepo 1mo
37
// And an ordinary file still renders, or the two rules above have eaten everything.
133728e barerepo 1mo
38
{"/john/johnbot/file/master/small.txt", []string{"one line"}, []string{"too large", "binary file"}},
133728e barerepo 1mo
39
}
133728e barerepo 1mo
40
for _, c := range cases {
133728e barerepo 1mo
41
code, _, body := get(t, in.http.URL+c.path)
133728e barerepo 1mo
42
if code != http.StatusOK {
133728e barerepo 1mo
43
t.Errorf("%s answered %d", c.path, code)
133728e barerepo 1mo
44
continue
133728e barerepo 1mo
45
}
133728e barerepo 1mo
46
for _, want := range c.want {
133728e barerepo 1mo
47
if !strings.Contains(body, want) {
133728e barerepo 1mo
48
t.Errorf("%s does not say %q", c.path, want)
133728e barerepo 1mo
49
}
133728e barerepo 1mo
50
}
133728e barerepo 1mo
51
for _, not := range c.not {
133728e barerepo 1mo
52
if strings.Contains(body, not) {
133728e barerepo 1mo
53
t.Errorf("%s put %q on the page", c.path, not)
133728e barerepo 1mo
54
}
133728e barerepo 1mo
55
}
133728e barerepo 1mo
56
}
133728e barerepo 1mo
57
133728e barerepo 1mo
58
// The download itself is an attachment and never a page, whatever the bytes are. 42.3.
133728e barerepo 1mo
59
code, _, _ := get(t, in.http.URL+"/john/johnbot/raw/master/logo.bin")
133728e barerepo 1mo
60
if code != http.StatusOK {
133728e barerepo 1mo
61
t.Errorf("the raw bytes answered %d", code)
133728e barerepo 1mo
62
}
133728e barerepo 1mo
63
}
history · rawbarerepo 0.1.0