From 4bb07b88b3a2656baa9fcd40deda098857792c03 Mon Sep 17 00:00:00 2001 From: gedi Date: Tue, 23 Feb 2016 11:47:39 +0200 Subject: [PATCH] closes #25 --- statement_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 statement_test.go diff --git a/statement_test.go b/statement_test.go new file mode 100644 index 0000000..93bd4ea --- /dev/null +++ b/statement_test.go @@ -0,0 +1,33 @@ +package sqlmock + +import ( + "errors" + "testing" +) + +// +build go1.6 + +func TestExpectedPreparedStatemtCloseError(t *testing.T) { + conn, mock, err := New() + if err != nil { + t.Fatalf("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.Fatalf("unexpected error while opening transaction:", err) + } + + stmt, err := txn.Prepare("SELECT") + if err != nil { + t.Fatalf("unexpected error while preparing a statement:", err) + } + + if err := stmt.Close(); err != want { + t.Fatalf("Got = %v, want = %v", err, want) + } +}