MCPcopy Create free account
hub / github.com/cli/cli / TestRequestWithContextPropagatesContext

Function TestRequestWithContextPropagatesContext

api/request_test.go:280–298  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
280func 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
300func TestDoRequest(t *testing.T) {
301 reg := &httpmock.Registry{}

Callers

nothing calls this directly

Calls 8

VerifyMethod · 0.95
RegisterMethod · 0.95
StatusStringResponseFunction · 0.92
newTestClientFunction · 0.85
ValueMethod · 0.80
RequestWithContextMethod · 0.80
EqualMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected