1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2024-11-24 08:32:36 +02:00
go-sqlmock/statement_test.go
2019-02-27 19:44:03 +00:00

34 lines
657 B
Go

// +build go1.6
package sqlmock
import (
"errors"
"testing"
)
func TestExpectedPreparedStatementCloseError(t *testing.T) {
conn, mock, err := New()
if err != nil {
t.Fatal("failed to open sqlmock database:", err)
}
mock.ExpectBegin()
want := errors.New("STMT ERROR")
mock.ExpectPrepare("SELECT").WillReturnCloseError(want)
txn, err := conn.Begin()
if err != nil {
t.Fatal("unexpected error while opening transaction:", err)
}
stmt, err := txn.Prepare("SELECT")
if err != nil {
t.Fatal("unexpected error while preparing a statement:", err)
}
if err := stmt.Close(); err != want {
t.Fatalf("got = %v, want = %v", err, want)
}
}