driftprogramming / pgxpoolmock

pgx postgresql pool
MIT License
38 stars 16 forks source link

rows.go Scan() crashes after QueryRow() #6

Open jlpettersson opened 2 years ago

jlpettersson commented 2 years ago

When I do a QueryRow() query, the Scan() panics with this error:

index out of range [-1]

This seem to be related to this line 72:

for i, col := range r.rows[r.pos-1] {

where r.pos is 0.

ncyellow commented 1 year ago

you need to add Next() call

this is a simple example

columns := []string{"id"}
pgxRows := pgxpoolmock.NewRows(columns).AddRow(100).ToPgxRows()
pgxRows.Next()

suite.mockPool.EXPECT().QueryRow(gomock.Any(), `
INSERT INTO "users"("login", "password")
VALUES ($1, $2)
returning "@users"`, user.Login, user.Password).Return(pgxRows)