fix(review round 1): daemon PAT-header auth, job pruning, session-split batches, streaming tars, seed cleanup, ping/pong, byte caps, branch switch, slug --, ctx cancel, Init:true, pagination, latest/before events; web newest-window history + load-older, offline busy gate, staleness guards, memo store, auth probe, scroll key, focus-visible, draft restore, poll dedup; 106+181 tests, coverage 96.2%/95.1%+
This commit is contained in:
@@ -4,8 +4,10 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -131,3 +133,63 @@ func TestGitLabReposSkipsEmptyPaths(t *testing.T) {
|
||||
t.Fatalf("repos = %+v, want empty (blank path skipped)", repos)
|
||||
}
|
||||
}
|
||||
|
||||
// newPagedGitLab serves full pages until pagesToFull+1, then a short page.
|
||||
func newPagedGitLab(t *testing.T, alwaysFull bool) *GitLab {
|
||||
t.Helper()
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/api/v1/user/repos", func(w http.ResponseWriter, r *http.Request) {
|
||||
page, _ := strconv.Atoi(r.URL.Query().Get("page"))
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
count := projectsPerPage
|
||||
if !alwaysFull && page > 2 {
|
||||
count = 1
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("[")
|
||||
for i := 0; i < count; i++ {
|
||||
if i > 0 {
|
||||
b.WriteString(",")
|
||||
}
|
||||
fmt.Fprintf(&b, `{"full_name":"team/p%d-%d","name":"P","owner":{"login":"team"},`+
|
||||
`"updated_at":"2024-01-01T00:00:00Z","html_url":"https://gl","default_branch":"main"}`, page, i)
|
||||
}
|
||||
b.WriteString("]")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(b.String()))
|
||||
})
|
||||
up := httptest.NewServer(mux)
|
||||
t.Cleanup(up.Close)
|
||||
store := openTestStore(t)
|
||||
if err := store.SetSetting(settingGitLabToken, "pat"); err != nil {
|
||||
t.Fatalf("set token: %v", err)
|
||||
}
|
||||
return NewGitLab(store, up.URL)
|
||||
}
|
||||
|
||||
func TestGitLabReposPaginatesUntilShortPage(t *testing.T) {
|
||||
gl := newPagedGitLab(t, false) // 50 + 50 + 1 (short) → stops after page 3
|
||||
repos, err := gl.Repos(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("repos: %v", err)
|
||||
}
|
||||
if len(repos) != 2*projectsPerPage+1 {
|
||||
t.Fatalf("repos = %d, want %d (pages 1-2 full + short page 3)", len(repos), 2*projectsPerPage+1)
|
||||
}
|
||||
if repos[0].Path != "team/p1-0" || repos[len(repos)-1].Path != "team/p3-0" {
|
||||
t.Fatalf("first/last = %q..%q, want page1..page3", repos[0].Path, repos[len(repos)-1].Path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGitLabReposPaginationCapped(t *testing.T) {
|
||||
gl := newPagedGitLab(t, true) // upstream always returns full pages
|
||||
repos, err := gl.Repos(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("repos: %v", err)
|
||||
}
|
||||
if len(repos) != maxRepoPages*projectsPerPage {
|
||||
t.Fatalf("repos = %d, want capped at %d", len(repos), maxRepoPages*projectsPerPage)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user