MCPcopy
hub / github.com/jackc/pgx / TestCollectRows

Function TestCollectRows

rows_test.go:161–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

159}
160
161func TestCollectRows(t *testing.T) {
162 defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
163 rows, _ := conn.Query(ctx, `select n from generate_series(0, 99) n`)
164 numbers, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (int32, error) {
165 var n int32
166 err := row.Scan(&n)
167 return n, err
168 })
169 require.NoError(t, err)
170
171 assert.Len(t, numbers, 100)
172 for i := range numbers {
173 assert.Equal(t, int32(i), numbers[i])
174 }
175 })
176}
177
178func TestCollectRowsEmpty(t *testing.T) {
179 defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

Callers

nothing calls this directly

Calls 4

RunTestMethod · 0.80
QueryMethod · 0.65
ScanMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected