go-sqlmock icon indicating copy to clipboard operation
go-sqlmock copied to clipboard

Unexpected result of argument matcher if no args expected but args supplied

Open IvoGoman opened this issue 3 years ago • 2 comments
trafficstars

Issue

Query is created dynamically in the code. Sometimes it will expect an arg and sometimes it won't. I expected that the mock would raise an error if the expectation is no query args but actually one is supplied.

Reproduction steps

https://go.dev/play/p/VwF9k6KlET2

Expected Result

Unexpected error ... arguments do not match: expected 0, but got 1 arguments

Actual Result

No error, expectations are met

Locally I have fixed this by removing: https://github.com/DATA-DOG/go-sqlmock/blob/fd316ea51261e47e4f20169cce71baee8dd21d91/expectations_go18.go#L32-L34

I expected that the mock should catch if an unexpected argument is passed. Be it on the mock or on the actual query in the productive code.

IvoGoman avatar Jul 14 '22 09:07 IvoGoman

If you feel like this is valid, then I am willing to open a PR with the mentioned fix. I saw some tests will need to be fixed.

IvoGoman avatar Jul 14 '22 09:07 IvoGoman

If you feel like this is valid, then I am willing to open a PR with the mentioned fix. I saw some tests will need to be fixed.

do it, wait for you pr

fatelei avatar Jul 30 '22 07:07 fatelei

@fatelei could you have a look at #295

IvoGoman avatar Aug 18 '22 15:08 IvoGoman