(t *testing.T)
| 387 | } |
| 388 | |
| 389 | func TestProjectsService_ListUserProjects_pagination(t *testing.T) { |
| 390 | t.Parallel() |
| 391 | client, mux, _ := setup(t) |
| 392 | mux.HandleFunc("/users/u/projectsV2", func(w http.ResponseWriter, r *http.Request) { |
| 393 | q := r.URL.Query() |
| 394 | after := q.Get("after") |
| 395 | before := q.Get("before") |
| 396 | if after == "" && before == "" { |
| 397 | w.Header().Set("Link", "<http://example.org/users/u/projectsV2?after=ucursor2>; rel=\"next\"") |
| 398 | fmt.Fprint(w, `[{"id":10,"title":"UP1","created_at":"2011-01-02T15:04:05Z","updated_at":"2012-01-02T15:04:05Z"}]`) |
| 399 | return |
| 400 | } |
| 401 | if after == "ucursor2" { |
| 402 | w.Header().Set("Link", "<http://example.org/users/u/projectsV2?before=ucursor2>; rel=\"prev\"") |
| 403 | fmt.Fprint(w, `[{"id":11,"title":"UP2","created_at":"2011-01-02T15:04:05Z","updated_at":"2012-01-02T15:04:05Z"}]`) |
| 404 | return |
| 405 | } |
| 406 | http.Error(w, "unexpected query", http.StatusBadRequest) |
| 407 | }) |
| 408 | ctx := t.Context() |
| 409 | first, resp, err := client.Projects.ListUserProjects(ctx, "u", nil) |
| 410 | if err != nil { |
| 411 | t.Fatalf("first page error: %v", err) |
| 412 | } |
| 413 | if len(first) != 1 || first[0].GetID() != 10 { |
| 414 | t.Fatalf("unexpected first page %+v", first) |
| 415 | } |
| 416 | if resp.After != "ucursor2" { |
| 417 | t.Fatalf("expected resp.After=ucursor2 got %q", resp.After) |
| 418 | } |
| 419 | |
| 420 | opts := &ListProjectsOptions{ListProjectsPaginationOptions: ListProjectsPaginationOptions{After: (resp.After)}} |
| 421 | second, resp2, err := client.Projects.ListUserProjects(ctx, "u", opts) |
| 422 | if err != nil { |
| 423 | t.Fatalf("second page error: %v", err) |
| 424 | } |
| 425 | if len(second) != 1 || second[0].GetID() != 11 { |
| 426 | t.Fatalf("unexpected second page %+v", second) |
| 427 | } |
| 428 | if resp2.Before != "ucursor2" { |
| 429 | t.Fatalf("expected resp2.Before=ucursor2 got %q", resp2.Before) |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | func TestProjectsService_ListUserProjects_error(t *testing.T) { |
| 434 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…