| 304 | } |
| 305 | |
| 306 | func TestCollectExactlyOneRowNotFound(t *testing.T) { |
| 307 | defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |
| 308 | rows, _ := conn.Query(ctx, `select 42 where false`) |
| 309 | n, err := pgx.CollectExactlyOneRow(rows, func(row pgx.CollectableRow) (int32, error) { |
| 310 | var n int32 |
| 311 | err := row.Scan(&n) |
| 312 | return n, err |
| 313 | }) |
| 314 | assert.ErrorIs(t, err, pgx.ErrNoRows) |
| 315 | assert.Equal(t, int32(0), n) |
| 316 | }) |
| 317 | } |
| 318 | |
| 319 | func TestCollectExactlyOneRowExtraRows(t *testing.T) { |
| 320 | defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |