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

Function Test_apiRun_arrayPaginationREST

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

Source from the content-addressed store, hash-verified

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