MCPcopy Index your code
hub / github.com/google/go-github / TestCheckResponse_AbuseRateLimit_TooManyRequests

Function TestCheckResponse_AbuseRateLimit_TooManyRequests

github/github_test.go:3390–3419  ·  view source on GitHub ↗

TestCheckResponse_AbuseRateLimit_TooManyRequests tests that HTTP 429 with secondary rate limit documentation_url is correctly detected as AbuseRateLimitError. GitHub API can return either 403 or 429 for secondary rate limits. See: https://docs.github.com/rest/using-the-rest-api/rate-limits-for-the-r

(t *testing.T)

Source from the content-addressed store, hash-verified

3388// GitHub API can return either 403 or 429 for secondary rate limits.
3389// See: https://docs.github.com/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits
3390func TestCheckResponse_AbuseRateLimit_TooManyRequests(t *testing.T) {
3391 t.Parallel()
3392 res := &http.Response{
3393 Request: &http.Request{},
3394 StatusCode: http.StatusTooManyRequests,
3395 Header: http.Header{},
3396 Body: io.NopCloser(strings.NewReader(`{"message":"m",
3397 "documentation_url": "https://docs.github.com/rest/overview/rate-limits-for-the-rest-api#about-secondary-rate-limits"}`)),
3398 }
3399 res.Header.Set(headerRetryAfter, "60")
3400
3401 var err *AbuseRateLimitError
3402 errors.As(CheckResponse(res), &err)
3403
3404 if err == nil {
3405 t.Fatal("Expected error response.")
3406 }
3407
3408 if err.Response != res {
3409 t.Errorf("Response = %v, want %v", err.Response, res)
3410 }
3411 if err.Message != "m" {
3412 t.Errorf("Message = %q, want %q", err.Message, "m")
3413 }
3414 if err.RetryAfter == nil {
3415 t.Error("Expected RetryAfter to be set")
3416 } else if *err.RetryAfter != 60*time.Second {
3417 t.Errorf("RetryAfter = %v, want %v", *err.RetryAfter, 60*time.Second)
3418 }
3419}
3420
3421func TestCheckResponse_RedirectionError(t *testing.T) {
3422 t.Parallel()

Callers

nothing calls this directly

Calls 2

CheckResponseFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…