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

barerepo / server / e2e/offlinereply_test.go
112 lines · 4.4kb · 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
"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 35.5 is two commands, and what they produce has to appear on the thread page.
133728e barerepo 1mo
12
func TestAReplyWrittenTheWayTheBookSaysAppearsOnThePage(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
mark := in.account("mark")
133728e barerepo 1mo
19
seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
20
133728e barerepo 1mo
21
resp := post(t, in, "john", "/john/johnbot/threads", url.Values{
133728e barerepo 1mo
22
"title": {"the reconnect loop spins"},
133728e barerepo 1mo
23
"body": {"it retries with no delay"},
133728e barerepo 1mo
24
})
133728e barerepo 1mo
25
if resp.StatusCode != http.StatusFound {
133728e barerepo 1mo
26
t.Fatalf("opening a thread answered %d", resp.StatusCode)
133728e barerepo 1mo
27
}
133728e barerepo 1mo
28
133728e barerepo 1mo
29
work := clone(t, in, mark, "/john/johnbot")
133728e barerepo 1mo
30
// 35.4's fetch is the wildcard one, because that is the line the book hands out.
133728e barerepo 1mo
31
run(t, work, "git", "fetch", "-q", in.url(mark, "/john/johnbot"), "refs/notes/*:refs/notes/*")
133728e barerepo 1mo
32
// 35.5 verbatim: a message and nothing else, with no header a reader would have to know about.
133728e barerepo 1mo
33
run(t, work, "git", "notes", "--ref=threads/1", "append", "-m", "I see the same problem.")
133728e barerepo 1mo
34
run(t, work, "git", "push", "-q", in.url(mark, "/john/johnbot"), "refs/notes/threads/1")
133728e barerepo 1mo
35
133728e barerepo 1mo
36
code, _, body := get(t, in.http.URL+"/john/johnbot/thread/1")
133728e barerepo 1mo
37
if code != http.StatusOK {
133728e barerepo 1mo
38
t.Fatalf("the thread answered %d", code)
133728e barerepo 1mo
39
}
133728e barerepo 1mo
40
if !strings.Contains(body, "I see the same problem.") {
133728e barerepo 1mo
41
t.Error("a reply pushed the way chapter 35.5 documents is not on the thread page")
133728e barerepo 1mo
42
}
133728e barerepo 1mo
43
// And it is attributed to mark, or john is shown saying words mark wrote.
133728e barerepo 1mo
44
if !strings.Contains(body, "mark") {
133728e barerepo 1mo
45
t.Error("the reply is on the page with no author, and the push knew who pushed it")
133728e barerepo 1mo
46
}
133728e barerepo 1mo
47
// The two must be separate comments, since one of them belongs to somebody else.
133728e barerepo 1mo
48
if strings.Count(body, `class="body"`) < 2 {
133728e barerepo 1mo
49
t.Error("the reply was merged into the comment above it, under that person's name")
133728e barerepo 1mo
50
}
133728e barerepo 1mo
51
if i, j := strings.Index(body, "it retries with no delay"), strings.Index(body, "mark"); i > j {
133728e barerepo 1mo
52
t.Error("the reply is above the comment it answers")
133728e barerepo 1mo
53
}
133728e barerepo 1mo
54
}
133728e barerepo 1mo
55
133728e barerepo 1mo
56
// A reply from the web is already a proper record, so the repair must leave it exactly alone.
133728e barerepo 1mo
57
func TestARepairDoesNotTouchAWellFormedReply(t *testing.T) {
133728e barerepo 1mo
58
if _, err := exec.LookPath("git"); err != nil {
133728e barerepo 1mo
59
t.Skip("git is not installed")
133728e barerepo 1mo
60
}
133728e barerepo 1mo
61
in := newInstance(t)
133728e barerepo 1mo
62
john := in.account("john")
133728e barerepo 1mo
63
mark := in.account("mark")
133728e barerepo 1mo
64
seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
65
133728e barerepo 1mo
66
post(t, in, "john", "/john/johnbot/threads", url.Values{
133728e barerepo 1mo
67
"title": {"a thread"}, "body": {"the first word"}})
133728e barerepo 1mo
68
post(t, in, "mark", "/john/johnbot/thread/1/reply", url.Values{"body": {"the second word"}})
133728e barerepo 1mo
69
133728e barerepo 1mo
70
// A mirror push of the whole ref changes nothing, so nothing may be re-attributed by it.
133728e barerepo 1mo
71
work := clone(t, in, mark, "/john/johnbot")
133728e barerepo 1mo
72
run(t, work, "git", "fetch", "-q", in.url(mark, "/john/johnbot"), "refs/notes/*:refs/notes/*")
133728e barerepo 1mo
73
run(t, work, "git", "push", "-q", in.url(mark, "/john/johnbot"), "refs/notes/threads/1")
133728e barerepo 1mo
74
133728e barerepo 1mo
75
_, _, body := get(t, in.http.URL+"/john/johnbot/thread/1")
133728e barerepo 1mo
76
if strings.Count(body, "the second word") != 1 {
133728e barerepo 1mo
77
t.Error("a push that changed nothing rewrote a comment")
133728e barerepo 1mo
78
}
133728e barerepo 1mo
79
if !strings.Contains(body, ">john</a>") || !strings.Contains(body, ">mark</a>") {
133728e barerepo 1mo
80
t.Errorf("a push that changed nothing lost an author:\n%s", body)
133728e barerepo 1mo
81
}
133728e barerepo 1mo
82
}
133728e barerepo 1mo
83
133728e barerepo 1mo
84
// A record that already names its author is kept as written, or chapter 40.3 cannot restore a repository.
133728e barerepo 1mo
85
func TestARestoredNoteKeepsTheAuthorItCarries(t *testing.T) {
133728e barerepo 1mo
86
if _, err := exec.LookPath("git"); err != nil {
133728e barerepo 1mo
87
t.Skip("git is not installed")
133728e barerepo 1mo
88
}
133728e barerepo 1mo
89
in := newInstance(t)
133728e barerepo 1mo
90
john := in.account("john")
133728e barerepo 1mo
91
mark := in.account("mark")
133728e barerepo 1mo
92
in.account("lisa")
133728e barerepo 1mo
93
seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
94
133728e barerepo 1mo
95
post(t, in, "john", "/john/johnbot/threads", url.Values{
133728e barerepo 1mo
96
"title": {"a thread"}, "body": {"the first word"}})
133728e barerepo 1mo
97
133728e barerepo 1mo
98
// Mark pushes a record lisa wrote, which is what restoring somebody else's repository is.
133728e barerepo 1mo
99
work := clone(t, in, mark, "/john/johnbot")
133728e barerepo 1mo
100
run(t, work, "git", "fetch", "-q", in.url(mark, "/john/johnbot"), "refs/notes/*:refs/notes/*")
133728e barerepo 1mo
101
run(t, work, "git", "notes", "--ref=threads/1", "append", "-m",
133728e barerepo 1mo
102
"--\nauthor: lisa\ntime: 1755000000\n\nlisa wrote this line")
133728e barerepo 1mo
103
run(t, work, "git", "push", "-q", in.url(mark, "/john/johnbot"), "refs/notes/threads/1")
133728e barerepo 1mo
104
133728e barerepo 1mo
105
_, _, body := get(t, in.http.URL+"/john/johnbot/thread/1")
133728e barerepo 1mo
106
if !strings.Contains(body, "lisa wrote this line") {
133728e barerepo 1mo
107
t.Fatalf("the pushed record is not on the page:\n%s", body)
133728e barerepo 1mo
108
}
133728e barerepo 1mo
109
if !strings.Contains(body, ">lisa</a>") {
133728e barerepo 1mo
110
t.Error("a record naming its own author was re-attributed to whoever pushed it")
133728e barerepo 1mo
111
}
133728e barerepo 1mo
112
}
history · rawbarerepo 0.1.0