vole
Clone
Read only, no credentials:
https://rodent.software/git/vole.git
Write over SSH with a registered key:
git clone ssh://git@0.0.0.0:2222/vole.git
A free and open-source forge that lives in your Git repo.
Merge change request 01M70WES5ZZDJ6RP226WB11BBZ: Let people rename and remove their own passkeys
keenan · 1h ago
4b8c9e1d
| 1 | package web |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestPaginateClampsToTheFeed(t *testing.T) { |
| 6 | events := make([]activityEvent, 120) |
| 7 | |
| 8 | page, p := paginate(events, 1, 50, instanceActivityURL(""), "Activity pages") |
| 9 | if len(page) != 50 || p.Page != 1 || p.Pages != 3 || p.From != 1 || p.To != 50 { |
| 10 | t.Fatalf("page 1 = len %d, %+v", len(page), p) |
| 11 | } |
| 12 | if p.PrevURL != "" || p.NextURL != "/-/activity?page=2" { |
| 13 | t.Fatalf("page 1 links = %q, %q", p.PrevURL, p.NextURL) |
| 14 | } |
| 15 | page, p = paginate(events, 2, 50, instanceActivityURL(""), "Activity pages") |
| 16 | if len(page) != 50 || p.PrevURL != "/-/activity" || p.NextURL != "/-/activity?page=3" { |
| 17 | t.Fatalf("page 2 = len %d, %+v", len(page), p) |
| 18 | } |
| 19 | page, p = paginate(events, 3, 50, instanceActivityURL(""), "Activity pages") |
| 20 | if len(page) != 20 || p.PrevURL != "/-/activity?page=2" || p.NextURL != "" { |
| 21 | t.Fatalf("page 3 = len %d, %+v", len(page), p) |
| 22 | } |
| 23 | if _, p = paginate(events, 99, 50, instanceActivityURL(""), "Activity pages"); p.Page != 3 { |
| 24 | t.Fatalf("page 99 clamped to %d, want 3", p.Page) |
| 25 | } |
| 26 | if _, p = paginate(events, 0, 50, instanceActivityURL(""), "Activity pages"); p.Page != 1 { |
| 27 | t.Fatalf("page 0 clamped to %d, want 1", p.Page) |
| 28 | } |
| 29 | if page, p = paginate(nil, 4, 50, instanceActivityURL(""), "Activity pages"); page != nil || p.Page != 1 || p.Pages != 1 { |
| 30 | t.Fatalf("empty feed = %v, %+v", page, p) |
| 31 | } |
| 32 | // A filtered feed keeps its filter in the page links: paging must not |
| 33 | // silently widen what the reader asked for. |
| 34 | if _, p = paginate(events, 1, 50, instanceActivityURL("issue"), "Activity pages"); p.NextURL != "/-/activity?kind=issue&page=2" { |
| 35 | t.Fatalf("filtered next URL = %q", p.NextURL) |
| 36 | } |
| 37 | // A page size below one is treated as one rather than dividing by zero. |
| 38 | if page, _ = paginate(events, 1, 0, instanceActivityURL(""), "Activity pages"); len(page) != 1 { |
| 39 | t.Fatalf("perPage 0 returned %d events, want 1", len(page)) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func TestPageSection(t *testing.T) { |
| 44 | cases := map[string]string{ |
| 45 | "/": "home", |
| 46 | "/demo": "repos", |
| 47 | "/demo/issues": "repos", |
| 48 | "/-/activity": "activity", |
| 49 | "/-/repos/new": "repos", |
| 50 | "/-/users": "admin", |
| 51 | "/-/users/keenan": "admin", |
| 52 | "/-/admin": "admin", |
| 53 | "/-/u": "people", |
| 54 | "/-/u/keenan": "people", |
| 55 | "/-/account": "account", |
| 56 | "/-/login": "", |
| 57 | "/-/status": "admin", |
| 58 | } |
| 59 | for path, want := range cases { |
| 60 | if got := pageSection(path); got != want { |
| 61 | t.Errorf("pageSection(%q) = %q, want %q", path, got, want) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 |