(t *testing.T)
| 487 | } |
| 488 | |
| 489 | func TestClientRetriesHTTP500(t *testing.T) { |
| 490 | t.Parallel() |
| 491 | |
| 492 | var attempts int |
| 493 | server := newGitHubServer(t, func(writer http.ResponseWriter, request *http.Request) { |
| 494 | if request.URL.Path != "/repos/acme/demo/releases/latest" { |
| 495 | http.NotFound(writer, request) |
| 496 | return |
| 497 | } |
| 498 | attempts++ |
| 499 | if attempts < 3 { |
| 500 | http.Error(writer, `{"message":"temporary failure"}`, http.StatusInternalServerError) |
| 501 | return |
| 502 | } |
| 503 | writeJSON( |
| 504 | writer, |
| 505 | `{"tag_name":"v1.2.3","draft":false,"prerelease":false,"tarball_url":"`+serverURLPlaceholder+`/downloads/source.tar.gz","assets":[]}`, |
| 506 | ) |
| 507 | }) |
| 508 | defer server.Close() |
| 509 | |
| 510 | client := NewClient( |
| 511 | server.URL, |
| 512 | WithRetryPolicy(time.Millisecond, time.Millisecond, 2), |
| 513 | WithSleep(func(context.Context, time.Duration) error { return nil }), |
| 514 | ) |
| 515 | _, err := client.fetchLatestRelease(context.Background(), repoSlug{owner: "acme", name: "demo", full: "acme/demo"}) |
| 516 | if err != nil { |
| 517 | t.Fatalf("fetchLatestRelease() error = %v", err) |
| 518 | } |
| 519 | if attempts != 3 { |
| 520 | t.Fatalf("attempts = %d, want 3", attempts) |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | func TestClientRetriesHTTP500LogsCloseErrorBeforeRetry(t *testing.T) { |
| 525 | t.Parallel() |
nothing calls this directly
no test coverage detected