TestCheckResponse_RateLimit_TooManyRequests tests that HTTP 429 with X-RateLimit-Remaining: 0 is correctly detected as RateLimitError. GitHub API can return either 403 or 429 for rate limiting. See: https://docs.github.com/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28
(t *testing.T)
| 3352 | // GitHub API can return either 403 or 429 for rate limiting. |
| 3353 | // See: https://docs.github.com/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28 |
| 3354 | func TestCheckResponse_RateLimit_TooManyRequests(t *testing.T) { |
| 3355 | t.Parallel() |
| 3356 | res := &http.Response{ |
| 3357 | Request: &http.Request{}, |
| 3358 | StatusCode: http.StatusTooManyRequests, |
| 3359 | Header: http.Header{}, |
| 3360 | Body: io.NopCloser(strings.NewReader(`{"message":"m", |
| 3361 | "documentation_url": "url"}`)), |
| 3362 | } |
| 3363 | res.Header.Set(HeaderRateLimit, "60") |
| 3364 | res.Header.Set(HeaderRateRemaining, "0") |
| 3365 | res.Header.Set(HeaderRateUsed, "60") |
| 3366 | res.Header.Set(HeaderRateReset, "243424") |
| 3367 | res.Header.Set(HeaderRateResource, "core") |
| 3368 | |
| 3369 | var err *RateLimitError |
| 3370 | errors.As(CheckResponse(res), &err) |
| 3371 | |
| 3372 | if err == nil { |
| 3373 | t.Error("Expected error response.") |
| 3374 | } |
| 3375 | |
| 3376 | want := &RateLimitError{ |
| 3377 | Rate: parseRate(res), |
| 3378 | Response: res, |
| 3379 | Message: "m", |
| 3380 | } |
| 3381 | if !errors.Is(err, want) { |
| 3382 | t.Errorf("Error = %#v, want %#v", err, want) |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | // TestCheckResponse_AbuseRateLimit_TooManyRequests tests that HTTP 429 with |
| 3387 | // secondary rate limit documentation_url is correctly detected as AbuseRateLimitError. |
nothing calls this directly
no test coverage detected
searching dependent graphs…