Call sites such as release asset upload run inside a retry loop that owns a context, so the context has to reach the outgoing request.
(t *testing.T)
| 278 | // Call sites such as release asset upload run inside a retry loop that owns a context, so the |
| 279 | // context has to reach the outgoing request. |
| 280 | func TestRequestWithContextPropagatesContext(t *testing.T) { |
| 281 | reg := &httpmock.Registry{} |
| 282 | defer reg.Verify(t) |
| 283 | client := newTestClient(reg) |
| 284 | |
| 285 | var gotValue any |
| 286 | reg.Register(httpmock.MatchAny, func(req *http.Request) (*http.Response, error) { |
| 287 | gotValue = req.Context().Value(ctxKey{}) |
| 288 | return httpmock.StatusStringResponse(200, "{}")(req) |
| 289 | }) |
| 290 | |
| 291 | ctx := context.WithValue(context.Background(), ctxKey{}, "carried") |
| 292 | |
| 293 | resp, err := client.RequestWithContext(ctx, "github.com", http.MethodGet, "repos/OWNER/REPO", nil) |
| 294 | require.NoError(t, err) |
| 295 | defer resp.Body.Close() |
| 296 | |
| 297 | assert.Equal(t, "carried", gotValue) |
| 298 | } |
| 299 | |
| 300 | func TestDoRequest(t *testing.T) { |
| 301 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected