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

Function Test_apiRun_paginationREST

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

Source from the content-addressed store, hash-verified

802}
803
804func Test_apiRun_paginationREST(t *testing.T) {
805 ios, _, stdout, stderr := iostreams.Test()
806
807 requestCount := 0
808 responses := []*http.Response{
809 {
810 Proto: "HTTP/1.1",
811 Status: "200 OK",
812 StatusCode: 200,
813 Body: io.NopCloser(bytes.NewBufferString(`{"page":1}`)),
814 Header: http.Header{
815 "Content-Type": []string{"application/json"},
816 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
817 "X-Github-Request-Id": []string{"1"},
818 },
819 },
820 {
821 Proto: "HTTP/1.1",
822 Status: "200 OK",
823 StatusCode: 200,
824 Body: io.NopCloser(bytes.NewBufferString(`{"page":2}`)),
825 Header: http.Header{
826 "Content-Type": []string{"application/json"},
827 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
828 "X-Github-Request-Id": []string{"2"},
829 },
830 },
831 {
832 Proto: "HTTP/1.1",
833 Status: "200 OK",
834 StatusCode: 200,
835 Body: io.NopCloser(bytes.NewBufferString(`{"page":3}`)),
836 Header: http.Header{
837 "Content-Type": []string{"application/json"},
838 "X-Github-Request-Id": []string{"3"},
839 },
840 },
841 }
842
843 options := ApiOptions{
844 IO: ios,
845 HttpClient: func(rootapi.HTTPClientOptions) (*http.Client, error) {
846 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
847 resp := responses[requestCount]
848 resp.Request = req
849 requestCount++
850 return resp, nil
851 }
852 return &http.Client{Transport: tr}, nil
853 },
854 Config: func() (gh.Config, error) {
855 return config.NewMockConfig(), nil
856 },
857
858 RequestMethod: "GET",
859 RequestMethodPassed: true,
860 RequestPath: "issues",
861 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