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

barerepo / server / e2e/blobsize_test.go
102 lines · 3.5kb · 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
"fmt"
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 20.2: LFS off is not enough without a size limit, and the message must name the file.
133728e barerepo 1mo
11
func TestAnOversizedBlobIsRejectedByName(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
setLimits(t, in, "\n[limits]\nmax_blob_mb = 1\n")
133728e barerepo 1mo
20
133728e barerepo 1mo
21
big := strings.Repeat("video frame padding, not source code\n", 60000)
133728e barerepo 1mo
22
write(t, work, "demo.mov", big)
133728e barerepo 1mo
23
write(t, work, "notes.txt", "small and fine\n")
133728e barerepo 1mo
24
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
25
run(t, work, "git", "commit", "-qm", "add a video")
133728e barerepo 1mo
26
133728e barerepo 1mo
27
out, err := try(t, work, "git", "push", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
28
if err == nil {
133728e barerepo 1mo
29
t.Fatalf("a 2mb blob was accepted against a 1mb limit:\n%s", out)
133728e barerepo 1mo
30
}
133728e barerepo 1mo
31
if !strings.Contains(out, "demo.mov") {
133728e barerepo 1mo
32
t.Errorf("the rejection does not name the file, so the user has to hunt:\n%s", out)
133728e barerepo 1mo
33
}
133728e barerepo 1mo
34
if !strings.Contains(out, "the limit is 1mb") {
133728e barerepo 1mo
35
t.Errorf("the rejection does not say what the limit is:\n%s", out)
133728e barerepo 1mo
36
}
133728e barerepo 1mo
37
if !strings.Contains(out, "object storage") {
133728e barerepo 1mo
38
t.Errorf("chapter 20.4 says to tell the user where large files belong:\n%s", out)
133728e barerepo 1mo
39
}
133728e barerepo 1mo
40
if strings.Contains(out, "notes.txt") {
133728e barerepo 1mo
41
t.Errorf("the rejection blames a file that is under the limit:\n%s", out)
133728e barerepo 1mo
42
}
133728e barerepo 1mo
43
133728e barerepo 1mo
44
// The push is all or nothing, so nothing landed.
133728e barerepo 1mo
45
if _, _, body := get(t, in.http.URL+"/john/johnbot"); strings.Contains(body, "add a video") {
133728e barerepo 1mo
46
t.Error("the rejected commit is on the log anyway")
133728e barerepo 1mo
47
}
133728e barerepo 1mo
48
}
133728e barerepo 1mo
49
133728e barerepo 1mo
50
// A push under the limit must not pay for the check with a rejection.
133728e barerepo 1mo
51
func TestASmallPushIsNotAffectedByTheBlobLimit(t *testing.T) {
133728e barerepo 1mo
52
if _, err := exec.LookPath("git"); err != nil {
133728e barerepo 1mo
53
t.Skip("git is not installed")
133728e barerepo 1mo
54
}
133728e barerepo 1mo
55
in := newInstance(t)
133728e barerepo 1mo
56
john := in.account("john")
133728e barerepo 1mo
57
work := seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
58
133728e barerepo 1mo
59
setLimits(t, in, "\n[limits]\nmax_blob_mb = 1\n")
133728e barerepo 1mo
60
133728e barerepo 1mo
61
write(t, work, "small.go", "package main\n\nfunc main() {}\n")
133728e barerepo 1mo
62
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
63
run(t, work, "git", "commit", "-qm", "a small change")
133728e barerepo 1mo
64
run(t, work, "git", "push", "-q", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
65
133728e barerepo 1mo
66
if _, _, body := get(t, in.http.URL+"/john/johnbot"); !strings.Contains(body, "a small change") {
133728e barerepo 1mo
67
t.Error("a push under the limit did not land")
133728e barerepo 1mo
68
}
133728e barerepo 1mo
69
}
133728e barerepo 1mo
70
133728e barerepo 1mo
71
// Chapter 20.2 bounds the whole push as well as one file in it, and the two are one pass of git.
133728e barerepo 1mo
72
func TestAPushOverTheWholeLimitIsRejected(t *testing.T) {
133728e barerepo 1mo
73
if _, err := exec.LookPath("git"); err != nil {
133728e barerepo 1mo
74
t.Skip("git is not installed")
133728e barerepo 1mo
75
}
133728e barerepo 1mo
76
in := newInstance(t)
133728e barerepo 1mo
77
john := in.account("john")
133728e barerepo 1mo
78
work := seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
79
setLimits(t, in, "\n[limits]\nmax_blob_mb = 4\nmax_push_mb = 1\n")
133728e barerepo 1mo
80
133728e barerepo 1mo
81
// Three files, each under the blob limit, together over the push limit.
133728e barerepo 1mo
82
for i := 0; i < 3; i++ {
133728e barerepo 1mo
83
write(t, work, fmt.Sprintf("part%d.bin", i),
133728e barerepo 1mo
84
strings.Repeat(fmt.Sprintf("chunk %d padding padding padding\n", i), 15000))
133728e barerepo 1mo
85
}
133728e barerepo 1mo
86
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
87
run(t, work, "git", "commit", "-qm", "a first import")
133728e barerepo 1mo
88
133728e barerepo 1mo
89
out, err := try(t, work, "git", "push", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
90
if err == nil {
133728e barerepo 1mo
91
t.Fatalf("a push over the whole limit was accepted:\n%s", out)
133728e barerepo 1mo
92
}
133728e barerepo 1mo
93
if strings.Contains(out, "part0.bin") {
133728e barerepo 1mo
94
t.Errorf("the whole push was refused by naming one file, which is the other limit:\n%s", out)
133728e barerepo 1mo
95
}
133728e barerepo 1mo
96
if !strings.Contains(out, "the limit is 1mb") {
133728e barerepo 1mo
97
t.Errorf("the rejection does not say what the limit is:\n%s", out)
133728e barerepo 1mo
98
}
133728e barerepo 1mo
99
if !strings.Contains(out, "max_push_mb") {
133728e barerepo 1mo
100
t.Errorf("the rejection does not say which setting to raise:\n%s", out)
133728e barerepo 1mo
101
}
133728e barerepo 1mo
102
}
history · rawbarerepo 0.1.0