| 159 | } |
| 160 | |
| 161 | func 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 | |
| 178 | func TestCollectRowsEmpty(t *testing.T) { |
| 179 | defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |