pgxpoolmock icon indicating copy to clipboard operation
pgxpoolmock copied to clipboard

rows.go Scan() crashes after QueryRow()

Open jlpettersson opened this issue 3 years ago • 1 comments

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.

jlpettersson avatar Aug 22 '22 10:08 jlpettersson

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)

ncyellow avatar Dec 19 '22 22:12 ncyellow