Skip to content

Commit

Permalink
Add test to validate CollectRows for empty Rows
Browse files Browse the repository at this point in the history
  • Loading branch information
its-felix committed Mar 5, 2024
1 parent da6f2c9 commit c4d466b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ func TestCollectRows(t *testing.T) {
})
}

func TestCollectRowsEmpty(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
rows, _ := conn.Query(ctx, `select n from generate_series(0, 0) n`)
numbers, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (int32, error) {
var n int32
err := row.Scan(&n)
return n, err
})
require.NoError(t, err)
require.NotNil(t, numbers)

assert.Empty(t, numbers)
})
}

// This example uses CollectRows with a manually written collector function. In most cases RowTo, RowToAddrOf,
// RowToStructByPos, RowToAddrOfStructByPos, or another generic function would be used.
func ExampleCollectRows() {
Expand Down

0 comments on commit c4d466b

Please sign in to comment.