Skip to content

Commit

Permalink
Merge pull request #314 from chrisirhc/patch-1
Browse files Browse the repository at this point in the history
WIP: Fix WillReturnRows(nil) in expectations_go18.go
  • Loading branch information
ninadingole authored Aug 13, 2024
2 parents 6bed17c + f3575cd commit 49e34f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion expectations_go18.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (e *ExpectedQuery) WillReturnRows(rows ...*Rows) *ExpectedQuery {
sets := make([]*Rows, len(rows))
for i, r := range rows {
sets[i] = r
if r.def != nil {
if r != nil && r.def != nil {
defs++
}
}
Expand Down
24 changes: 24 additions & 0 deletions expectations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,27 @@ func TestExecWithNoArgsAndWithArgsPanic(t *testing.T) {
mock := &sqlmock{}
mock.ExpectExec("^INSERT INTO user").WithArgs("John").WithoutArgs()
}


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

db, mock, err := New()
if err != nil {
t.Fatal(err)
}
defer db.Close()

defer func() {
if err := recover(); err != nil {
t.Error(err)
}
}()

mock.ExpectQuery("SELECT (.+) FROM users WHERE (.+)").WithArgs("test").WillReturnRows(nil)
query := "SELECT name, email FROM users WHERE name = ?"
_, err = mock.(*sqlmock).Query(query, []driver.Value{"test"})
if err != nil {
t.Error(err)
}
}

0 comments on commit 49e34f6

Please sign in to comment.