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

Function Test_apiRun_paginationREST

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

Source from the content-addressed store, hash-verified

770}
771
772func Test_apiRun_paginationREST(t *testing.T) {
773 ios, _, stdout, stderr := iostreams.Test()
774
775 requestCount := 0
776 responses := []*http.Response{
777 {
778 Proto: "HTTP/1.1",
779 Status: "200 OK",
780 StatusCode: 200,
781 Body: io.NopCloser(bytes.NewBufferString(`{"page":1}`)),
782 Header: http.Header{
783 "Content-Type": []string{"application/json"},
784 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
785 "X-Github-Request-Id": []string{"1"},
786 },
787 },
788 {
789 Proto: "HTTP/1.1",
790 Status: "200 OK",
791 StatusCode: 200,
792 Body: io.NopCloser(bytes.NewBufferString(`{"page":2}`)),
793 Header: http.Header{
794 "Content-Type": []string{"application/json"},
795 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
796 "X-Github-Request-Id": []string{"2"},
797 },
798 },
799 {
800 Proto: "HTTP/1.1",
801 Status: "200 OK",
802 StatusCode: 200,
803 Body: io.NopCloser(bytes.NewBufferString(`{"page":3}`)),
804 Header: http.Header{
805 "Content-Type": []string{"application/json"},
806 "X-Github-Request-Id": []string{"3"},
807 },
808 },
809 }
810
811 options := ApiOptions{
812 IO: ios,
813 HttpClient: func() (*http.Client, error) {
814 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
815 resp := responses[requestCount]
816 resp.Request = req
817 requestCount++
818 return resp, nil
819 }
820 return &http.Client{Transport: tr}, nil
821 },
822 Config: func() (gh.Config, error) {
823 return config.NewMockConfig(), nil
824 },
825
826 RequestMethod: "GET",
827 RequestMethodPassed: true,
828 RequestPath: "issues",
829 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