rendercaps_test.go
⎇
Raw
1package e2e
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestRenderCapsAndNonASCIIPaths(t *testing.T) {
9 e := newEnv(t, "MAX_RENDER_BYTES", "2000")
10 admin := e.admin()
11 e.createRepo(admin, "caps")
12 e.seedRepo("caps", map[string]string{
13 "README.md": "# small\n",
14 "docs/README.md": strings.Repeat("big readme line\n", 200),
15 })
16 small := e.seedRepo("caps", map[string]string{
17 "dir/ä ö.txt": "umlaut\n",
18 "bin/bild ü.bin": "\x00\x01\x02binary",
19 }, "non-ASCII names")
20
21 t.Run("non-ASCII name links to a working blob", func(t *testing.T) {
22 r := admin.get("/caps/tree/main/dir").mustStatus(200)
23 if got := r.Text(".file-name a[href*='/blob/']"); got != "ä ö.txt" {
24 t.Fatalf("tree name = %q", got)
25 }
26 admin.get(r.Attr(".file-name a[href*='/blob/']", "href")).mustStatus(200)
27 })
28
29 t.Run("commit diff shows unquoted paths and binary sizes", func(t *testing.T) {
30 r := admin.get("/caps/commit/" + small).mustStatus(200)
31 if !r.Contains("ä ö.txt") || !r.Contains("bild ü.bin") || r.Contains(`\303`) {
32 t.Fatal("diff paths are missing or C-quoted")
33 }
34 })
35
36 t.Run("oversized README shows a download notice", func(t *testing.T) {
37 r := admin.get("/caps/tree/main/docs").mustStatus(200)
38 if !r.Contains("README too large to display inline") || r.Contains("big readme line") {
39 t.Fatal("oversized README was rendered")
40 }
41 if href := r.Attr(".readme-section .file-download-notice a", "href"); href != "/caps/raw/main/docs/README.md" {
42 t.Fatalf("download href = %q", href)
43 }
44 if r := admin.get("/caps").mustStatus(200); !r.Has(".readme-section .markdown-body") {
45 t.Fatal("small root README not rendered")
46 }
47 })
48
49 t.Run("oversized commit diff is not rendered", func(t *testing.T) {
50 big := e.seedRepo("caps", map[string]string{"big.txt": strings.Repeat("line\n", 1000)}, "big")
51 r := admin.get("/caps/commit/" + big).mustStatus(200)
52 if !r.Contains("Diff is too large to render inline") || r.Has(".diff-file") {
53 t.Fatal("oversized diff was rendered")
54 }
55 })
56}
57