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

Function Test_apiRun_paginationGraphQL

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

Source from the content-addressed store, hash-verified

1089}
1090
1091func Test_apiRun_paginationGraphQL(t *testing.T) {
1092 ios, _, stdout, stderr := iostreams.Test()
1093
1094 requestCount := 0
1095 responses := []*http.Response{
1096 {
1097 StatusCode: 200,
1098 Header: http.Header{"Content-Type": []string{`application/json`}},
1099 Body: io.NopCloser(bytes.NewBufferString(heredoc.Doc(`
1100 {
1101 "data": {
1102 "nodes": ["page one"],
1103 "pageInfo": {
1104 "endCursor": "PAGE1_END",
1105 "hasNextPage": true
1106 }
1107 }
1108 }`))),
1109 },
1110 {
1111 StatusCode: 200,
1112 Header: http.Header{"Content-Type": []string{`application/json`}},
1113 Body: io.NopCloser(bytes.NewBufferString(heredoc.Doc(`
1114 {
1115 "data": {
1116 "nodes": ["page two"],
1117 "pageInfo": {
1118 "endCursor": "PAGE2_END",
1119 "hasNextPage": false
1120 }
1121 }
1122 }`))),
1123 },
1124 }
1125
1126 options := ApiOptions{
1127 IO: ios,
1128 HttpClient: func(rootapi.HTTPClientOptions) (*http.Client, error) {
1129 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
1130 resp := responses[requestCount]
1131 resp.Request = req
1132 requestCount++
1133 return resp, nil
1134 }
1135 return &http.Client{Transport: tr}, nil
1136 },
1137 Config: func() (gh.Config, error) {
1138 return config.NewMockConfig(), nil
1139 },
1140
1141 RawFields: []string{"foo=bar"},
1142 RequestMethod: "POST",
1143 RequestPath: "graphql",
1144 Paginate: true,
1145 }
1146
1147 err := apiRun(&options)
1148 require.NoError(t, err)

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