1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2025-03-19 20:57:50 +02:00
go-sqlmock/statement_test.go

34 lines
657 B
Go
Raw Normal View History

2016-02-23 11:48:45 +02:00
// +build go1.6
2016-02-23 11:47:39 +02:00
package sqlmock
import (
"errors"
"testing"
)
2019-02-27 19:44:03 +00:00
func TestExpectedPreparedStatementCloseError(t *testing.T) {
2016-02-23 11:47:39 +02:00
conn, mock, err := New()
if err != nil {
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 {
t.Fatal("unexpected error while opening transaction:", err)
2016-02-23 11:47:39 +02:00
}
stmt, err := txn.Prepare("SELECT")
if err != nil {
t.Fatal("unexpected error while preparing a statement:", err)
2016-02-23 11:47:39 +02:00
}
if err := stmt.Close(); err != want {
2019-02-27 19:44:03 +00:00
t.Fatalf("got = %v, want = %v", err, want)
2016-02-23 11:47:39 +02:00
}
}