1
0
mirror of https://github.com/zhashkevych/go-sqlxmock.git synced 2025-06-12 21:47:29 +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

@ -9,14 +9,21 @@ import (
var mock = &Sqlmock{}
func ExampleNewErrorResult() {
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
}
func ExampleNewResult() {
var lastInsertID, affected int64
result := NewResult(lastInsertID, affected)
mock.ExpectExec("^INSERT (.+)").WillReturnResult(result)
fmt.Println(mock.ExpectationsWereMet())
// Output: there is a remaining expectation *sqlmock.ExpectedExec which was not matched yet
}
func TestShouldReturnValidSqlDriverResult(t *testing.T) {