You've already forked go-sqlmock
mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-06-16 23:57:35 +02:00
allow to set errors for rows scan
* 9a36c2e more examples and tests for rows * 908877e cannot mock rows.Columns error so far
This commit is contained in:
@ -2,6 +2,7 @@ package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
@ -71,3 +72,13 @@ func TestQueryExpectationSqlMatch(t *testing.T) {
|
||||
t.Errorf("Sql must have matched the query")
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleExpectExec() {
|
||||
db, mock, _ := New()
|
||||
result := NewErrorResult(fmt.Errorf("some error"))
|
||||
mock.ExpectExec("^INSERT (.+)").WillReturnResult(result)
|
||||
res, _ := db.Exec("INSERT something")
|
||||
_, err := res.LastInsertId()
|
||||
fmt.Println(err)
|
||||
// Output: some error
|
||||
}
|
||||
|
Reference in New Issue
Block a user