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

Function TestRequestReturnsBodyUnread

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

Source from the content-addressed store, hash-verified

121}
122
123func TestRequestReturnsBodyUnread(t *testing.T) {
124 reg := &httpmock.Registry{}
125 defer reg.Verify(t)
126 client := newTestClient(reg)
127
128 reg.Register(httpmock.MatchAny, httpmock.StatusStringResponse(200, "the raw body"))
129
130 resp, err := client.Request("github.com", http.MethodGet, "repos/OWNER/REPO/contents/f", nil)
131 require.NoError(t, err)
132 defer resp.Body.Close()
133
134 body, err := io.ReadAll(resp.Body)
135 require.NoError(t, err)
136 assert.Equal(t, "the raw body", string(body))
137}
138
139// REST treats 204 and 205 specially and decodes every other 2xx as JSON. Request must do neither,
140// so that bodiless successes and non-JSON successes both work.

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected