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

barerepo / server / e2e/notespush_test.go
67 lines · 2.2kb · 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 19.2: participation is subscription, and a reply pushed from a clone is a reply.
133728e barerepo 1mo
12
func TestAReplyPushedFromACloneReachesTheInbox(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
// John opens a thread here, which is the door that already recorded an event.
133728e barerepo 1mo
22
resp := post(t, in, "john", "/john/johnbot/threads", url.Values{
133728e barerepo 1mo
23
"title": {"the reconnect loop spins"},
133728e barerepo 1mo
24
"body": {"it retries with no delay"},
133728e barerepo 1mo
25
})
133728e barerepo 1mo
26
if resp.StatusCode != http.StatusFound {
133728e barerepo 1mo
27
t.Fatalf("opening a thread answered %d", resp.StatusCode)
133728e barerepo 1mo
28
}
133728e barerepo 1mo
29
133728e barerepo 1mo
30
// Mark replies the other way, by pushing a note from his clone, which chapter 3 calls the point.
133728e barerepo 1mo
31
work := clone(t, in, mark, "/john/johnbot")
133728e barerepo 1mo
32
run(t, work, "git", "fetch", "-q", in.url(mark, "/john/johnbot"),
133728e barerepo 1mo
33
"refs/notes/threads/1:refs/notes/threads/1")
133728e barerepo 1mo
34
run(t, work, "git", "notes", "--ref=threads/1", "append", "-m",
133728e barerepo 1mo
35
"mark\ntime: 2026-08-19T00:00:00Z\n\nseen it on a flaky link too")
133728e barerepo 1mo
36
run(t, work, "git", "push", "-q", in.url(mark, "/john/johnbot"),
133728e barerepo 1mo
37
"refs/notes/threads/1:refs/notes/threads/1")
133728e barerepo 1mo
38
133728e barerepo 1mo
39
// John owns the repository, so the reply must be in his inbox.
133728e barerepo 1mo
40
body := inboxOf(t, in, "john")
133728e barerepo 1mo
41
if !strings.Contains(body, "mark replied") {
133728e barerepo 1mo
42
t.Errorf("a reply pushed from a clone is not in the owner's inbox:\n%s", body)
133728e barerepo 1mo
43
}
133728e barerepo 1mo
44
// And mark took part, so he hears about what comes next without pressing anything.
133728e barerepo 1mo
45
if body := inboxOf(t, in, "mark"); !strings.Contains(body, "reconnect loop") {
133728e barerepo 1mo
46
t.Errorf("pushing a reply did not subscribe the author to the thread:\n%s", body)
133728e barerepo 1mo
47
}
133728e barerepo 1mo
48
}
133728e barerepo 1mo
49
133728e barerepo 1mo
50
func inboxOf(t *testing.T, in *instance, account string) string {
133728e barerepo 1mo
51
t.Helper()
133728e barerepo 1mo
52
token, err := in.db.NewSession(t.Context(), account)
133728e barerepo 1mo
53
if err != nil {
133728e barerepo 1mo
54
t.Fatal(err)
133728e barerepo 1mo
55
}
133728e barerepo 1mo
56
req, err := http.NewRequest(http.MethodGet, in.http.URL+"/inbox", nil)
133728e barerepo 1mo
57
if err != nil {
133728e barerepo 1mo
58
t.Fatal(err)
133728e barerepo 1mo
59
}
133728e barerepo 1mo
60
req.AddCookie(&http.Cookie{Name: "barerepo_session", Value: token})
133728e barerepo 1mo
61
resp, err := http.DefaultClient.Do(req)
133728e barerepo 1mo
62
if err != nil {
133728e barerepo 1mo
63
t.Fatal(err)
133728e barerepo 1mo
64
}
133728e barerepo 1mo
65
defer resp.Body.Close()
133728e barerepo 1mo
66
return readAll(t, resp)
133728e barerepo 1mo
67
}
history · rawbarerepo 0.1.0