| 291 | } |
| 292 | |
| 293 | func TestCollectExactlyOneRow(t *testing.T) { |
| 294 | defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |
| 295 | rows, _ := conn.Query(ctx, `select 42`) |
| 296 | n, err := pgx.CollectExactlyOneRow(rows, func(row pgx.CollectableRow) (int32, error) { |
| 297 | var n int32 |
| 298 | err := row.Scan(&n) |
| 299 | return n, err |
| 300 | }) |
| 301 | assert.NoError(t, err) |
| 302 | assert.Equal(t, int32(42), n) |
| 303 | }) |
| 304 | } |
| 305 | |
| 306 | func TestCollectExactlyOneRowNotFound(t *testing.T) { |
| 307 | defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |