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:1018–1089  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1016}
1017
1018func Test_apiRun_arrayPaginationREST_with_headers(t *testing.T) {
1019 ios, _, stdout, stderr := iostreams.Test()
1020
1021 requestCount := 0
1022 responses := []*http.Response{
1023 {
1024 Proto: "HTTP/1.1",
1025 Status: "200 OK",
1026 StatusCode: 200,
1027 Body: io.NopCloser(bytes.NewBufferString(`[{"page":1}]`)),
1028 Header: http.Header{
1029 "Content-Type": []string{"application/json"},
1030 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=2>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
1031 "X-Github-Request-Id": []string{"1"},
1032 },
1033 },
1034 {
1035 Proto: "HTTP/1.1",
1036 Status: "200 OK",
1037 StatusCode: 200,
1038 Body: io.NopCloser(bytes.NewBufferString(`[{"page":2}]`)),
1039 Header: http.Header{
1040 "Content-Type": []string{"application/json"},
1041 "Link": []string{`<https://api.github.com/repositories/1227/issues?page=3>; rel="next", <https://api.github.com/repositories/1227/issues?page=3>; rel="last"`},
1042 "X-Github-Request-Id": []string{"2"},
1043 },
1044 },
1045 {
1046 Proto: "HTTP/1.1",
1047 Status: "200 OK",
1048 StatusCode: 200,
1049 Body: io.NopCloser(bytes.NewBufferString(`[{"page":3}]`)),
1050 Header: http.Header{
1051 "Content-Type": []string{"application/json"},
1052 "X-Github-Request-Id": []string{"3"},
1053 },
1054 },
1055 }
1056
1057 options := ApiOptions{
1058 IO: ios,
1059 HttpClient: func(rootapi.HTTPClientOptions) (*http.Client, error) {
1060 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
1061 resp := responses[requestCount]
1062 resp.Request = req
1063 requestCount++
1064 return resp, nil
1065 }
1066 return &http.Client{Transport: tr}, nil
1067 },
1068 Config: func() (gh.Config, error) {
1069 return config.NewMockConfig(), nil
1070 },
1071
1072 RequestMethod: "GET",
1073 RequestMethodPassed: true,
1074 RequestPath: "issues",
1075 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