https://github.com/DATA-DOG/go-sqlmock/pull/295 introduced stricter checking of query arguments. This results in new test failures when using e.g. ExpectedQuery or ExpectedExec without WithArgs(..) and the actual query passes arguments. This case of no expected arguments but actual arguments passed was previously not caught.
However, there is also the case where queries are matched via QueryMatcherRegexp and there is no intention to strictly validate the actual arguments. This case broke with the above mentioned change and requires rather cumbersome fixing as such:
// this would fail with arguments do not match: expected 0, but got 6 arguments
mock.ExpectExec("INSERT .*foobar::foobar.*").WillReturnResult(sqlmock.NewResult(0, 1))
...
// this would be the fix
mock.ExpectExec("INSERT .*foobar::foobar*").WithArgs(sqlmock.AnyArg(), sqlmock.AnyArg(), sqlmock.AnyArg(), sqlmock.AnyArg(), sqlmock.AnyArg(), sqlmock.AnyArg()).WillReturnResult(sqlmock.NewResult(0, 1))
In order to allow for both strict and relaxed matching of the expectations this change adds WithoutArgs(). This new Method on ExpectedQuery and ExpectedExec allows to strictly ensure that the actual query does not pass any arguments.
This reverts the strict argument checking introduced with https://github.com/DATA-DOG/go-sqlmock/pull/295 and makes this behavior opt-in.
Furthermore, a test will panic if both WithArgs(..) and WithoutArgs() are used together.
https://github.com/DATA-DOG/go-sqlmock/pull/295 introduced stricter checking of query arguments. This results in new test failures when using e.g.
ExpectedQuery
orExpectedExec
withoutWithArgs(..)
and the actual query passes arguments. This case of no expected arguments but actual arguments passed was previously not caught.However, there is also the case where queries are matched via
QueryMatcherRegexp
and there is no intention to strictly validate the actual arguments. This case broke with the above mentioned change and requires rather cumbersome fixing as such:In order to allow for both strict and relaxed matching of the expectations this change adds
WithoutArgs()
. This new Method onExpectedQuery
andExpectedExec
allows to strictly ensure that the actual query does not pass any arguments. This reverts the strict argument checking introduced with https://github.com/DATA-DOG/go-sqlmock/pull/295 and makes this behavior opt-in. Furthermore, a test will panic if bothWithArgs(..)
andWithoutArgs()
are used together.