-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
sqlmock panics when closing empty Rows object #337
Comments
Hi @raxod502-plaid! Thank you for your report. You are right that it shouldn't panic, that's a bug. It is also true that Quick facts:
Correct usage:
Consider a more complex example: const myQuery := `
SELECT disabled FROM users WHERE id = ?;
DELETE FROM logins WHERE created_at < ?;
`
tx.QueryContext(ctx, myQuery, theID, theTimestamp) That's a query returning two RowSets, the first one with a single column, and the second with none. A test expectation for it would be like: mock.ExpectQuery(myQuery).WithoutArgs().WillReturnRows(
mock.NewRows([]string{"disabled"}),
mock.NewRows(nil),
) Conclusions:
|
#314 will fix this issue |
Operating system and Go Version
macOS 14.4.1, Go 1.20
Issue
When using
db.Query
to perform a query that does not return any rows, sqlmock panics instead of performing a no-op as other database drivers do.A workaround is to use
db.Exec
instead so that there is no rows object to close, but the sqlmock behavior is incorrect.Reproduction steps
Expected Result
No error (or, at worst, an error returned from
rows.Close
)Actual Result
The text was updated successfully, but these errors were encountered: