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

Function TestRESTWithNext

api/client_test.go:193–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

191}
192
193func TestRESTWithNext(t *testing.T) {
194 reg := &httpmock.Registry{}
195 defer reg.Verify(t)
196 client := newTestClient(reg)
197
198 reg.Register(httpmock.MatchAny, func(req *http.Request) (*http.Response, error) {
199 return &http.Response{
200 Request: req,
201 StatusCode: http.StatusOK,
202 Body: io.NopCloser(bytes.NewBufferString(`{"name": "item"}`)),
203 Header: http.Header{
204 "Content-Type": {"application/json"},
205 "Link": {`<https://api.github.com/repos/owner/repo/items?page=2>; rel="next", <https://api.github.com/repos/owner/repo/items?page=3>; rel="last"`},
206 },
207 }, nil
208 })
209
210 response := struct {
211 Name string `json:"name"`
212 }{}
213 next, err := client.RESTWithNext("github.com", http.MethodGet, "repos/owner/repo/items", nil, &response)
214
215 require.NoError(t, err)
216 assert.Equal(t, "item", response.Name)
217 assert.Equal(t, "https://api.github.com/repos/owner/repo/items?page=2", next)
218}
219
220func TestRESTWithNextNoContent(t *testing.T) {
221 reg := &httpmock.Registry{}

Callers

nothing calls this directly

Calls 5

VerifyMethod · 0.95
RegisterMethod · 0.95
newTestClientFunction · 0.85
EqualMethod · 0.80
RESTWithNextMethod · 0.65

Tested by

no test coverage detected