MCPcopy Create free account
hub / github.com/compozy/agh / TestClientRetriesHTTP500

Function TestClientRetriesHTTP500

internal/registry/github/client_test.go:489–522  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

487}
488
489func 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
524func TestClientRetriesHTTP500LogsCloseErrorBeforeRetry(t *testing.T) {
525 t.Parallel()

Callers

nothing calls this directly

Calls 8

fetchLatestReleaseMethod · 0.95
newGitHubServerFunction · 0.85
writeJSONFunction · 0.70
NewClientFunction · 0.70
WithRetryPolicyFunction · 0.70
WithSleepFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected