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

Function Test_apiRun_paginationREST

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

Source from the content-addressed store, hash-verified

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