pashagolub / pgxmock

pgx mock driver for golang to test database interactions
Other
393 stars 49 forks source link

error not returned when scanning into an invalid kind in rows.Scan #209

Closed jjdiorio closed 4 months ago

jjdiorio commented 5 months ago

Describe the bug When scanning a row into an invalid type such as a string into an int an error should be returned. As of v3.40 and later the error is being ignored. It looks like it may be due to the error being ignored rather than returned here: https://github.com/pashagolub/pgxmock/blob/master/rows.go#L50

To Reproduce

import (
    "context"
    "github.com/pashagolub/pgxmock/v3"
    "github.com/stretchr/testify/assert"
    "testing"
)

func Test_QueryScanProblem(t *testing.T) {
    mockSql, _ := pgxmock.NewPool()
    ctx := context.Background()

    mockSql.ExpectQuery(`select id from example_table limit 1`).WillReturnRows(
        mockSql.NewRows([]string{"seq"}).AddRow("not-an-int"),
    )

    row := mockSql.QueryRow(ctx, `select id from example_table limit 1`)
    var expectedInt int
    err := row.Scan(&expectedInt)

    assert.ErrorContains(t, err, "Destination kind 'int' not supported for value kind")
}

Expected behavior The error triggered here: https://github.com/pashagolub/pgxmock/blob/master/rows.go#L142 should be returned instead of a nil error.

pashagolub commented 4 months ago

Hi James! Thanks for the info. Can you confirm #211 fixes your workflow?

jjdiorio commented 4 months ago

Hi Pavlo. https://github.com/pashagolub/pgxmock/pull/211 definitely resolves it for all of my use cases