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

Function Test_apiRun_arrayPaginationREST_with_headers

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

Source from the content-addressed store, hash-verified

946}
947
948func Test_apiRun_arrayPaginationREST_with_headers(t *testing.T) {
949 ios, _, stdout, stderr := iostreams.Test()
950
951 requestCount := 0
952 responses := []*http.Response{
953 {
954 Proto: "HTTP/1.1",
955 Status: "200 OK",
956 StatusCode: 200,
957 Body: io.NopCloser(bytes.NewBufferString(`[{"page":1}]`)),
958 Header: http.Header{
959 "Content-Type": []string{"application/json"},
960 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
961 "X-Github-Request-Id": []string{"1"},
962 },
963 },
964 {
965 Proto: "HTTP/1.1",
966 Status: "200 OK",
967 StatusCode: 200,
968 Body: io.NopCloser(bytes.NewBufferString(`[{"page":2}]`)),
969 Header: http.Header{
970 "Content-Type": []string{"application/json"},
971 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
972 "X-Github-Request-Id": []string{"2"},
973 },
974 },
975 {
976 Proto: "HTTP/1.1",
977 Status: "200 OK",
978 StatusCode: 200,
979 Body: io.NopCloser(bytes.NewBufferString(`[{"page":3}]`)),
980 Header: http.Header{
981 "Content-Type": []string{"application/json"},
982 "X-Github-Request-Id": []string{"3"},
983 },
984 },
985 }
986
987 options := ApiOptions{
988 IO: ios,
989 HttpClient: func(rootapi.HTTPClientOptions) (*http.Client, error) {
990 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
991 resp := responses[requestCount]
992 resp.Request = req
993 requestCount++
994 return resp, nil
995 }
996 return &http.Client{Transport: tr}, nil
997 },
998 Config: func() (gh.Config, error) {
999 return config.NewMockConfig(), nil
1000 },
1001
1002 RequestMethod: "GET",
1003 RequestMethodPassed: true,
1004 RequestPath: "issues",
1005 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