MCPcopy
hub / github.com/cli/cli / TestJsonArrayWriter_Copy

Function TestJsonArrayWriter_Copy

pkg/cmd/api/pagination_test.go:228–264  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

226}
227
228func TestJsonArrayWriter_Copy(t *testing.T) {
229 tests := []struct {
230 name string
231 limit int
232 }{
233 {
234 name: "unlimited",
235 },
236 {
237 name: "limited",
238 limit: 2,
239 },
240 }
241
242 for _, tt := range tests {
243 t.Run(tt.name, func(t *testing.T) {
244 buf := &bytes.Buffer{}
245 w := &jsonArrayWriter{
246 Writer: buf,
247 }
248
249 r := &noWriteToReader{
250 Reader: bytes.NewBufferString(`[1,2]`),
251 limit: tt.limit,
252 }
253
254 require.NoError(t, startPage(w))
255
256 n, err := io.Copy(w, r)
257 require.NoError(t, err)
258 assert.Equal(t, int64(5), n)
259
260 require.NoError(t, w.Close())
261 assert.Equal(t, `[[1,2]]`, buf.String())
262 })
263 }
264}
265
266type noWriteToReader struct {
267 io.Reader

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
startPageFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
CopyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected