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

Function TestDoRequest

api/request_test.go:300–323  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

298}
299
300func TestDoRequest(t *testing.T) {
301 reg := &httpmock.Registry{}
302 defer reg.Verify(t)
303 client := newTestClient(reg)
304
305 reg.Register(httpmock.MatchAny, httpmock.StatusStringResponse(201, `{"id": 1}`))
306
307 // Fields such as ContentLength are the reason DoRequest exists, so assert one survives.
308 req, err := http.NewRequest(http.MethodPost, "https://uploads.github.com/assets", strings.NewReader("longer-than-assigned-content-length"))
309 require.NoError(t, err)
310 req.ContentLength = 1
311
312 resp, err := client.DoRequest(req)
313 require.NoError(t, err)
314 defer resp.Body.Close()
315
316 assert.Equal(t, 201, resp.StatusCode)
317 assert.Equal(t, "uploads.github.com", reg.Requests[0].URL.Hostname())
318 assert.Equal(t, int64(1), reg.Requests[0].ContentLength)
319
320 body, err := io.ReadAll(resp.Body)
321 require.NoError(t, err)
322 assert.Equal(t, `{"id": 1}`, string(body))
323}
324
325func TestDoRequestError(t *testing.T) {
326 reg := &httpmock.Registry{}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected