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

Function TestDoRequestError

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

Source from the content-addressed store, hash-verified

323}
324
325func TestDoRequestError(t *testing.T) {
326 reg := &httpmock.Registry{}
327 defer reg.Verify(t)
328 client := newTestClient(reg)
329
330 reg.Register(httpmock.MatchAny, httpmock.StatusJSONResponse(422, map[string]any{
331 "message": "Validation Failed",
332 }))
333
334 req, err := http.NewRequest(http.MethodPost, "https://uploads.github.com/assets", nil)
335 require.NoError(t, err)
336
337 resp, err := client.DoRequest(req)
338 assert.Nil(t, resp)
339
340 var httpErr HTTPError
341 require.ErrorAs(t, err, &httpErr)
342 assert.Equal(t, 422, httpErr.StatusCode)
343 assert.Equal(t, "Validation Failed", httpErr.Message)
344}
345
346// The transport built by NewHTTPClient supplies default Accept, Content-Type and User-Agent
347// headers. Per-request headers are only useful if they win against that real transport, so this

Callers

nothing calls this directly

Calls 6

VerifyMethod · 0.95
RegisterMethod · 0.95
StatusJSONResponseFunction · 0.92
newTestClientFunction · 0.85
DoRequestMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected