MCPcopy Index your code
hub / github.com/coder/coder / TestResponseErrorFromKeyPool

Function TestResponseErrorFromKeyPool

aibridge/intercept/openai_errors_test.go:15–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestResponseErrorFromKeyPool(t *testing.T) {
16 t.Parallel()
17
18 tests := []struct {
19 name string
20 keyPoolErr *keypool.Error
21 expectedStatus int
22 expectedRetryAfter time.Duration
23 }{
24 {
25 // Rate-limited with no cooldown: 429, no Retry-After.
26 name: "rate_limited_zero_retry_after",
27 keyPoolErr: &keypool.Error{Kind: keypool.ErrorKindRateLimited},
28 expectedStatus: http.StatusTooManyRequests,
29 expectedRetryAfter: 0,
30 },
31 {
32 // Rate-limited with cooldown: 429, Retry-After set.
33 name: "rate_limited_with_retry_after",
34 keyPoolErr: &keypool.Error{Kind: keypool.ErrorKindRateLimited, RetryAfter: 5 * time.Second},
35 expectedStatus: http.StatusTooManyRequests,
36 expectedRetryAfter: 5 * time.Second,
37 },
38 {
39 // Permanent: 502 api_error.
40 name: "permanent_returns_502",
41 keyPoolErr: &keypool.Error{Kind: keypool.ErrorKindPermanent},
42 expectedStatus: http.StatusBadGateway,
43 },
44 }
45
46 for _, tc := range tests {
47 t.Run(tc.name, func(t *testing.T) {
48 t.Parallel()
49 got := intercept.ResponseErrorFromKeyPool(tc.keyPoolErr)
50 require.NotNil(t, got)
51 assert.Equal(t, tc.expectedStatus, got.StatusCode)
52 assert.Equal(t, tc.expectedRetryAfter, got.RetryAfter)
53 })
54 }
55}

Callers

nothing calls this directly

Calls 3

ResponseErrorFromKeyPoolFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected