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

Function Test_apiRun_arrayPaginationREST

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

Source from the content-addressed store, hash-verified

842}
843
844func Test_apiRun_arrayPaginationREST(t *testing.T) {
845 ios, _, stdout, stderr := iostreams.Test()
846 ios.SetStdoutTTY(false)
847
848 requestCount := 0
849 responses := []*http.Response{
850 {
851 StatusCode: 200,
852 Body: io.NopCloser(bytes.NewBufferString(`[{"item":1},{"item":2}]`)),
853 Header: http.Header{
854 "Content-Type": []string{"application/json"},
855 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
856 },
857 },
858 {
859 StatusCode: 200,
860 Body: io.NopCloser(bytes.NewBufferString(`[{"item":3},{"item":4}]`)),
861 Header: http.Header{
862 "Content-Type": []string{"application/json"},
863 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
864 },
865 },
866 {
867 StatusCode: 200,
868 Body: io.NopCloser(bytes.NewBufferString(`[{"item":5}]`)),
869 Header: http.Header{
870 "Content-Type": []string{"application/json"},
871 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=4>; rel="next", <https://api.github.com/repositories/1227/issues?page=4>; rel="last"`},
872 },
873 },
874 {
875 StatusCode: 200,
876 Body: io.NopCloser(bytes.NewBufferString(`[]`)),
877 Header: http.Header{
878 "Content-Type": []string{"application/json"},
879 },
880 },
881 }
882
883 options := ApiOptions{
884 IO: ios,
885 HttpClient: func() (*http.Client, error) {
886 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
887 resp := responses[requestCount]
888 resp.Request = req
889 requestCount++
890 return resp, nil
891 }
892 return &http.Client{Transport: tr}, nil
893 },
894 Config: func() (gh.Config, error) {
895 return config.NewMockConfig(), nil
896 },
897
898 RequestMethod: "GET",
899 RequestMethodPassed: true,
900 RequestPath: "issues",
901 Paginate: true,

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected