MCPcopy
hub / github.com/cli/cli / TestJsonArrayWriter

Function TestJsonArrayWriter

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

Source from the content-addressed store, hash-verified

172}
173
174func TestJsonArrayWriter(t *testing.T) {
175 tests := []struct {
176 name string
177 pages []string
178 want string
179 }{
180 {
181 name: "empty",
182 pages: nil,
183 want: "[]",
184 },
185 {
186 name: "single array",
187 pages: []string{`[1,2]`},
188 want: `[[1,2]]`,
189 },
190 {
191 name: "multiple arrays",
192 pages: []string{`[1,2]`, `[3]`},
193 want: `[[1,2],[3]]`,
194 },
195 {
196 name: "single object",
197 pages: []string{`{"foo":1,"bar":"a"}`},
198 want: `[{"foo":1,"bar":"a"}]`,
199 },
200 {
201 name: "multiple pages",
202 pages: []string{`{"foo":1,"bar":"a"}`, `{"foo":2,"bar":"b"}`},
203 want: `[{"foo":1,"bar":"a"},{"foo":2,"bar":"b"}]`,
204 },
205 }
206
207 for _, tt := range tests {
208 t.Run(tt.name, func(t *testing.T) {
209 buf := &bytes.Buffer{}
210 w := &jsonArrayWriter{
211 Writer: buf,
212 }
213
214 for _, page := range tt.pages {
215 require.NoError(t, startPage(w))
216
217 n, err := w.Write([]byte(page))
218 require.NoError(t, err)
219 assert.Equal(t, len(page), n)
220 }
221
222 require.NoError(t, w.Close())
223 assert.Equal(t, tt.want, buf.String())
224 })
225 }
226}
227
228func TestJsonArrayWriter_Copy(t *testing.T) {
229 tests := []struct {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected