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

Function Test_apiRun_arrayPaginationREST

pkg/cmd/api/api_test.go:946–1016  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

944}
945
946func Test_apiRun_arrayPaginationREST(t *testing.T) {
947 ios, _, stdout, stderr := iostreams.Test()
948 ios.SetStdoutTTY(false)
949
950 requestCount := 0
951 responses := []*http.Response{
952 {
953 StatusCode: 200,
954 Body: io.NopCloser(bytes.NewBufferString(`[{"item":1},{"item":2}]`)),
955 Header: http.Header{
956 "Content-Type": []string{"application/json"},
957 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
958 },
959 },
960 {
961 StatusCode: 200,
962 Body: io.NopCloser(bytes.NewBufferString(`[{"item":3},{"item":4}]`)),
963 Header: http.Header{
964 "Content-Type": []string{"application/json"},
965 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
966 },
967 },
968 {
969 StatusCode: 200,
970 Body: io.NopCloser(bytes.NewBufferString(`[{"item":5}]`)),
971 Header: http.Header{
972 "Content-Type": []string{"application/json"},
973 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=4>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
974 },
975 },
976 {
977 StatusCode: 200,
978 Body: io.NopCloser(bytes.NewBufferString(`[]`)),
979 Header: http.Header{
980 "Content-Type": []string{"application/json"},
981 },
982 },
983 }
984
985 options := ApiOptions{
986 IO: ios,
987 HttpClient: func(rootapi.HTTPClientOptions) (*http.Client, error) {
988 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
989 resp := responses[requestCount]
990 resp.Request = req
991 requestCount++
992 return resp, nil
993 }
994 return &http.Client{Transport: tr}, nil
995 },
996 Config: func() (gh.Config, error) {
997 return config.NewMockConfig(), nil
998 },
999
1000 RequestMethod: "GET",
1001 RequestMethodPassed: true,
1002 RequestPath: "issues",
1003 Paginate: true,

Callers

nothing calls this directly

Calls 6

TestFunction · 0.92
NewMockConfigFunction · 0.92
apiRunFunction · 0.85
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected