MCPcopy
hub / github.com/cli/cli / Test_apiRun_arrayPaginationREST

Function Test_apiRun_arrayPaginationREST

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

Source from the content-addressed store, hash-verified

762}
763
764func Test_apiRun_arrayPaginationREST(t *testing.T) {
765 ios, _, stdout, stderr := iostreams.Test()
766 ios.SetStdoutTTY(false)
767
768 requestCount := 0
769 responses := []*http.Response{
770 {
771 StatusCode: 200,
772 Body: io.NopCloser(bytes.NewBufferString(`[{"item":1},{"item":2}]`)),
773 Header: http.Header{
774 "Content-Type": []string{"application/json"},
775 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
776 },
777 },
778 {
779 StatusCode: 200,
780 Body: io.NopCloser(bytes.NewBufferString(`[{"item":3},{"item":4}]`)),
781 Header: http.Header{
782 "Content-Type": []string{"application/json"},
783 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
784 },
785 },
786 {
787 StatusCode: 200,
788 Body: io.NopCloser(bytes.NewBufferString(`[{"item":5}]`)),
789 Header: http.Header{
790 "Content-Type": []string{"application/json"},
791 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=4>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
792 },
793 },
794 {
795 StatusCode: 200,
796 Body: io.NopCloser(bytes.NewBufferString(`[]`)),
797 Header: http.Header{
798 "Content-Type": []string{"application/json"},
799 },
800 },
801 }
802
803 options := ApiOptions{
804 IO: ios,
805 HttpClient: func() (*http.Client, error) {
806 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
807 resp := responses[requestCount]
808 resp.Request = req
809 requestCount++
810 return resp, nil
811 }
812 return &http.Client{Transport: tr}, nil
813 },
814 Config: func() (gh.Config, error) {
815 return config.NewBlankConfig(), nil
816 },
817
818 RequestMethod: "GET",
819 RequestMethodPassed: true,
820 RequestPath: "issues",
821 Paginate: true,

Callers

nothing calls this directly

Calls 6

TestFunction · 0.92
NewBlankConfigFunction · 0.92
apiRunFunction · 0.85
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected