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)
| 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 |
| 3390 | func 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 | |
| 3421 | func TestCheckResponse_RedirectionError(t *testing.T) { |
| 3422 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…