alwaysNextPageHandler returns a REST handler that always advertises another page via the Link header, regardless of the page requested. It drives a pagination loop purely off the page cap so tests can assert ui_get stops at uiGetMaxPages and sets has_more=true. The same body is returned for every pa
(t *testing.T, body any)
| 77 | // has_more=true. The same body is returned for every page, so the number of items |
| 78 | // collected equals the number of pages fetched. |
| 79 | func alwaysNextPageHandler(t *testing.T, body any) http.HandlerFunc { |
| 80 | t.Helper() |
| 81 | return func(w http.ResponseWriter, r *http.Request) { |
| 82 | page := 1 |
| 83 | if p := r.URL.Query().Get("page"); p != "" { |
| 84 | if parsed, err := strconv.Atoi(p); err == nil { |
| 85 | page = parsed |
| 86 | } |
| 87 | } |
| 88 | w.Header().Set("Link", fmt.Sprintf(`<https://api.github.com/next?page=%d>; rel="next"`, page+1)) |
| 89 | w.Header().Set("Content-Type", "application/json") |
| 90 | w.WriteHeader(http.StatusOK) |
| 91 | _ = json.NewEncoder(w).Encode(body) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func Test_UIGet(t *testing.T) { |
| 96 | // Verify tool definition |
no test coverage detected