@@ -134,11 +134,27 @@ type ExpectedQuery struct {
134134// WithArgs will match given expected args to actual database query arguments.
135135// if at least one argument does not match, it will return an error. For specific
136136// arguments an sqlmock.Argument interface can be used to match an argument.
137+ // Must not be used together with WithoutArgs()
137138func (e * ExpectedQuery ) WithArgs (args ... driver.Value ) * ExpectedQuery {
139+ if e .noArgs {
140+ panic ("WithArgs() and WithoutArgs() must not be used together" )
141+ }
138142 e .args = args
139143 return e
140144}
141145
146+ // WithoutArgs will ensure that no arguments are passed for this query.
147+ // if at least one argument is passed, it will return an error. This allows
148+ // for stricter validation of the query arguments.
149+ // Must no be used together with WithArgs()
150+ func (e * ExpectedQuery ) WithoutArgs () * ExpectedQuery {
151+ if len (e .args ) > 0 {
152+ panic ("WithoutArgs() and WithArgs() must not be used together" )
153+ }
154+ e .noArgs = true
155+ return e
156+ }
157+
142158// RowsWillBeClosed expects this query rows to be closed.
143159func (e * ExpectedQuery ) RowsWillBeClosed () * ExpectedQuery {
144160 e .rowsMustBeClosed = true
@@ -195,11 +211,27 @@ type ExpectedExec struct {
195211// WithArgs will match given expected args to actual database exec operation arguments.
196212// if at least one argument does not match, it will return an error. For specific
197213// arguments an sqlmock.Argument interface can be used to match an argument.
214+ // Must not be used together with WithoutArgs()
198215func (e * ExpectedExec ) WithArgs (args ... driver.Value ) * ExpectedExec {
216+ if len (e .args ) > 0 {
217+ panic ("WithArgs() and WithoutArgs() must not be used together" )
218+ }
199219 e .args = args
200220 return e
201221}
202222
223+ // WithoutArgs will ensure that no args are passed for this expected database exec action.
224+ // if at least one argument is passed, it will return an error. This allows for stricter
225+ // validation of the query arguments.
226+ // Must not be used together with WithArgs()
227+ func (e * ExpectedExec ) WithoutArgs () * ExpectedExec {
228+ if len (e .args ) > 0 {
229+ panic ("WithoutArgs() and WithArgs() must not be used together" )
230+ }
231+ e .noArgs = true
232+ return e
233+ }
234+
203235// WillReturnError allows to set an error for expected database exec action
204236func (e * ExpectedExec ) WillReturnError (err error ) * ExpectedExec {
205237 e .err = err
@@ -338,6 +370,7 @@ type queryBasedExpectation struct {
338370 expectSQL string
339371 converter driver.ValueConverter
340372 args []driver.Value
373+ noArgs bool // ensure no args are passed
341374}
342375
343376// ExpectedPing is used to manage *sql.DB.Ping expectations.
0 commit comments