MCPcopy Index your code
hub / github.com/coder/coder / TestFetchBranchDiff_Ratelimit

Function TestFetchBranchDiff_Ratelimit

coderd/externalauth/gitprovider/github_test.go:615–647  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

613}
614
615func 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
649func TestFetchPullRequestStatus(t *testing.T) {
650 t.Parallel()

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
ClientMethod · 0.95
NewFunction · 0.92
AsMethod · 0.80
SetMethod · 0.65
WriteMethod · 0.65
FetchBranchDiffMethod · 0.65
AddMethod · 0.65
ContainsMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected