1
0
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:
gedi
2015-07-22 16:17:35 +03:00
parent a071483cba
commit dc0efdab8f
5 changed files with 261 additions and 11 deletions

View File

@ -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
}