DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
5.95k stars 404 forks source link

Fix args passed not exp #295

Closed IvoGoman closed 1 year ago

IvoGoman commented 1 year ago

This PR changes the behavior in the expectation matching. Previously if no query arg was expected but one was actually passed during query execution the expectations were still met. (Example https://go.dev/play/p/VwF9k6KlET2 ) With this change it is ensured that expected and actual query args do always match.

This should be considered a breaking change as it changes the behavior how expectations are matched and can result in failing unit tests.

I was not able to run the tests locally against go < 1.8. The install of multiple go version mentioned here (https://go.dev/doc/manage-install#installing-multiple) did not work. There seems to be no darwin-arm64 version hosted for 1.7.6

Resolves #292

fatelei commented 1 year ago

good job

jameshalsall commented 7 months ago

This was included in a bugfix release but as the author noted it's a breaking change in behaviour.

Gilthoniel commented 7 months ago

As @jameshalsall , this is breaking change as you may very well write tests before v1.5.1 that were not interested in the given arguments but the processing of the result for instance.

Could we have something like this to enable this behavior instead ?

_, mockDB, _ := sqlmock.New()
mockDB.MatchArgumentsStrict(true)

(thank you for the library btw!)

IvoGoman commented 7 months ago

Opened https://github.com/DATA-DOG/go-sqlmock/pull/329 to make this stricter args checking an opt-in.