Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jjdiorio opened this issue Jul 3, 2024 · 2 comments · Fixed by #211
Closed

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

jjdiorio opened this issue Jul 3, 2024 · 2 comments · Fixed by #211
Assignees
Labels
bug Something isn't working

Comments

@jjdiorio
Copy link

jjdiorio commented Jul 3, 2024

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 pashagolub self-assigned this Jul 5, 2024
@pashagolub pashagolub added the bug Something isn't working label Jul 5, 2024
@pashagolub pashagolub linked a pull request Jul 16, 2024 that will close this issue
@pashagolub
Copy link
Owner

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

@jjdiorio
Copy link
Author

jjdiorio commented Jul 22, 2024

Hi Pavlo. #211 definitely resolves it for all of my use cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants