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

Function Test_apiRun_arrayPaginationREST

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

Source from the content-addressed store, hash-verified

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