2016-02-23 11:48:45 +02:00
|
|
|
// +build go1.6
|
|
|
|
|
2016-02-23 11:47:39 +02:00
|
|
|
package sqlmock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExpectedPreparedStatemtCloseError(t *testing.T) {
|
|
|
|
conn, mock, err := New()
|
|
|
|
if err != nil {
|
2016-02-26 14:45:18 +02:00
|
|
|
t.Fatal("failed to open sqlmock database:", err)
|
2016-02-23 11:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mock.ExpectBegin()
|
|
|
|
want := errors.New("STMT ERROR")
|
|
|
|
mock.ExpectPrepare("SELECT").WillReturnCloseError(want)
|
|
|
|
|
|
|
|
txn, err := conn.Begin()
|
|
|
|
if err != nil {
|
2016-02-26 14:45:18 +02:00
|
|
|
t.Fatal("unexpected error while opening transaction:", err)
|
2016-02-23 11:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stmt, err := txn.Prepare("SELECT")
|
|
|
|
if err != nil {
|
2016-02-26 14:45:18 +02:00
|
|
|
t.Fatal("unexpected error while preparing a statement:", err)
|
2016-02-23 11:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := stmt.Close(); err != want {
|
|
|
|
t.Fatalf("Got = %v, want = %v", err, want)
|
|
|
|
}
|
|
|
|
}
|