Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ type ExpectedExec struct {
// arguments an sqlmock.Argument interface can be used to match an argument.
// Must not be used together with WithoutArgs()
func (e *ExpectedExec) WithArgs(args ...driver.Value) *ExpectedExec {
if len(e.args) > 0 {
if e.noArgs {
panic("WithArgs() and WithoutArgs() must not be used together")
}
e.args = args
Expand Down
11 changes: 11 additions & 0 deletions expectations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ func TestExecWithNoArgsAndWithArgsPanic(t *testing.T) {
mock.ExpectExec("^INSERT INTO user").WithArgs("John").WithoutArgs()
}

func TestExecWithoutArgsAndWithArgsPanic(t *testing.T) {
const expectedPanic = "WithArgs() and WithoutArgs() must not be used together"
defer func() {
if r := recover(); r != expectedPanic {
t.Fatalf("expected panic %q, got %v", expectedPanic, r)
}
}()
mock := &sqlmock{}
mock.ExpectExec("UPDATE invoices SET status = \\?").WithoutArgs().WithArgs("paid")
}


func TestQueryWillReturnsNil(t *testing.T) {
t.Parallel()
Expand Down