Pagination deploy fix
This commit is contained in:
@@ -226,18 +226,52 @@ func TestDeployWikiReportsLiveExecutionProgress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeBBNamespacePaginationRejectsRepeatedCursor(t *testing.T) {
|
||||
func TestNodeBBNamespacePaginationStopsWhenRepeatedCursorReturnsNoNewPages(t *testing.T) {
|
||||
requests := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests++
|
||||
if requests > 2 {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"response": map[string]any{
|
||||
"pages": []map[string]any{},
|
||||
"pages": []map[string]any{
|
||||
{"tid": 2461, "title": "Favored Enemy: Elves", "titleLeaf": "Favored Enemy: Elves"},
|
||||
},
|
||||
"hasMore": true,
|
||||
"nextCursor": "same-cursor",
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := newNodeBBClient(server.URL, "nodebb-token")
|
||||
pages, err := client.listNamespacePages(9)
|
||||
if err != nil {
|
||||
t.Fatalf("expected repeated cursor with duplicate pages to stop cleanly, got %v", err)
|
||||
}
|
||||
if len(pages) != 1 || pages[0].TID != 2461 {
|
||||
t.Fatalf("expected one unique page from repeated cursor response, got %#v", pages)
|
||||
}
|
||||
if requests != 2 {
|
||||
t.Fatalf("expected pagination to stop after repeated cursor, got %d requests", requests)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeBBNamespacePaginationRejectsRepeatedCursorWithNewPages(t *testing.T) {
|
||||
requests := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests++
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
pages := []map[string]any{
|
||||
{"tid": 1, "title": "First", "titleLeaf": "First"},
|
||||
}
|
||||
if requests == 2 {
|
||||
pages = []map[string]any{
|
||||
{"tid": 2, "title": "Second", "titleLeaf": "Second"},
|
||||
}
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"response": map[string]any{
|
||||
"pages": pages,
|
||||
"hasMore": true,
|
||||
"nextCursor": "same-cursor",
|
||||
},
|
||||
@@ -248,14 +282,11 @@ func TestNodeBBNamespacePaginationRejectsRepeatedCursor(t *testing.T) {
|
||||
client := newNodeBBClient(server.URL, "nodebb-token")
|
||||
_, err := client.listNamespacePages(9)
|
||||
if err == nil {
|
||||
t.Fatal("expected repeated cursor error")
|
||||
t.Fatal("expected repeated cursor with new pages to fail")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "repeated pagination cursor") {
|
||||
t.Fatalf("expected repeated cursor error, got %v", err)
|
||||
}
|
||||
if requests != 2 {
|
||||
t.Fatalf("expected pagination to stop after repeated cursor, got %d requests", requests)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectLocalPagesReadsGeneratedPageIDFromMarkerWhenPathIsTitleBased(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user