(t *testing.T)
| 613 | } |
| 614 | |
| 615 | func TestFetchBranchDiff_Ratelimit(t *testing.T) { |
| 616 | t.Parallel() |
| 617 | |
| 618 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 619 | if strings.Contains(r.URL.Path, "/compare/") { |
| 620 | // Second request: compare endpoint returns 429. |
| 621 | w.Header().Set("Retry-After", "60") |
| 622 | w.WriteHeader(http.StatusTooManyRequests) |
| 623 | _, _ = w.Write([]byte(`{"message": "rate limit"}`)) |
| 624 | return |
| 625 | } |
| 626 | // First request: repo metadata. |
| 627 | w.Header().Set("Content-Type", "application/json") |
| 628 | _, _ = w.Write([]byte(`{"default_branch":"main"}`)) |
| 629 | })) |
| 630 | defer srv.Close() |
| 631 | |
| 632 | gp, err := gitprovider.New("github", srv.URL+"/api/v3", srv.Client()) |
| 633 | require.NoError(t, err) |
| 634 | require.NotNil(t, gp) |
| 635 | |
| 636 | _, err = gp.FetchBranchDiff( |
| 637 | context.Background(), |
| 638 | "test-token", |
| 639 | gitprovider.BranchRef{Owner: "org", Repo: "repo", Branch: "feat"}, |
| 640 | ) |
| 641 | require.Error(t, err) |
| 642 | |
| 643 | var rlErr *gitprovider.RateLimitError |
| 644 | require.True(t, errors.As(err, &rlErr), "error should be *RateLimitError, got: %T", err) |
| 645 | expected := time.Now().Add(60 * time.Second) |
| 646 | assert.WithinDuration(t, expected.Add(gitprovider.RateLimitPadding), rlErr.RetryAfter, 5*time.Second) |
| 647 | } |
| 648 | |
| 649 | func TestFetchPullRequestStatus(t *testing.T) { |
| 650 | t.Parallel() |
nothing calls this directly
no test coverage detected