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

Function Test_apiRun_paginationREST

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

Source from the content-addressed store, hash-verified

872}
873
874func Test_apiRun_paginationREST(t *testing.T) {
875 ios, _, stdout, stderr := iostreams.Test()
876
877 requestCount := 0
878 responses := []*http.Response{
879 {
880 Proto: "HTTP/1.1",
881 Status: "200 OK",
882 StatusCode: 200,
883 Body: io.NopCloser(bytes.NewBufferString(`{"page":1}`)),
884 Header: http.Header{
885 "Content-Type": []string{"application/json"},
886 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
887 "X-Github-Request-Id": []string{"1"},
888 },
889 },
890 {
891 Proto: "HTTP/1.1",
892 Status: "200 OK",
893 StatusCode: 200,
894 Body: io.NopCloser(bytes.NewBufferString(`{"page":2}`)),
895 Header: http.Header{
896 "Content-Type": []string{"application/json"},
897 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
898 "X-Github-Request-Id": []string{"2"},
899 },
900 },
901 {
902 Proto: "HTTP/1.1",
903 Status: "200 OK",
904 StatusCode: 200,
905 Body: io.NopCloser(bytes.NewBufferString(`{"page":3}`)),
906 Header: http.Header{
907 "Content-Type": []string{"application/json"},
908 "X-Github-Request-Id": []string{"3"},
909 },
910 },
911 }
912
913 options := ApiOptions{
914 IO: ios,
915 HttpClient: func(rootapi.HTTPClientOptions) (*http.Client, error) {
916 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
917 resp := responses[requestCount]
918 resp.Request = req
919 requestCount++
920 return resp, nil
921 }
922 return &http.Client{Transport: tr}, nil
923 },
924 Config: func() (gh.Config, error) {
925 return config.NewMockConfig(), nil
926 },
927
928 RequestMethod: "GET",
929 RequestMethodPassed: true,
930 RequestPath: "issues",
931 Paginate: true,

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected