You've already forked go-sqlxmock
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:
@ -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) {
|
||||
|
Reference in New Issue
Block a user