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

Function TestAbuseRateLimitError

github/github_test.go:4227–4279  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4225}
4226
4227func TestAbuseRateLimitError(t *testing.T) {
4228 t.Parallel()
4229 u, err := url.Parse("https://example.com")
4230 if err != nil {
4231 t.Fatal(err)
4232 }
4233
4234 t.Run("nil RetryAfter", func(t *testing.T) {
4235 t.Parallel()
4236 r := &AbuseRateLimitError{
4237 Response: &http.Response{
4238 Request: &http.Request{Method: "PUT", URL: u},
4239 StatusCode: http.StatusTooManyRequests,
4240 },
4241 Message: "<msg>",
4242 }
4243 if got, want := r.Error(), "PUT https://example.com: 429 <msg>"; got != want {
4244 t.Errorf("AbuseRateLimitError = %q, want %q", got, want)
4245 }
4246 })
4247
4248 t.Run("with RetryAfter", func(t *testing.T) {
4249 t.Parallel()
4250 d := 60 * time.Second
4251 r := &AbuseRateLimitError{
4252 Response: &http.Response{
4253 Request: &http.Request{Method: "GET", URL: u},
4254 StatusCode: http.StatusForbidden,
4255 },
4256 Message: "rate limited",
4257 RetryAfter: &d,
4258 }
4259 if got, want := r.Error(), "GET https://example.com: 403 rate limited [retry after 1m0s]"; got != want {
4260 t.Errorf("AbuseRateLimitError = %q, want %q", got, want)
4261 }
4262 })
4263
4264 t.Run("zero RetryAfter", func(t *testing.T) {
4265 t.Parallel()
4266 d := 0 * time.Second
4267 r := &AbuseRateLimitError{
4268 Response: &http.Response{
4269 Request: &http.Request{Method: "POST", URL: u},
4270 StatusCode: http.StatusForbidden,
4271 },
4272 Message: "rate limited",
4273 RetryAfter: &d,
4274 }
4275 if got, want := r.Error(), "POST https://example.com: 403 rate limited"; got != want {
4276 t.Errorf("AbuseRateLimitError = %q, want %q", got, want)
4277 }
4278 })
4279}
4280
4281func TestBareDo_returnsOpenBody(t *testing.T) {
4282 t.Parallel()

Callers

nothing calls this directly

Calls 2

ErrorMethod · 0.95
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…