@@ -153,7 +153,7 @@ import (
153
153
// will test that order with a different status, cannot be cancelled
154
154
func TestShouldNotCancelOrderWithNonPendingStatus (t *testing .T ) {
155
155
// open database stub
156
- db , err := sql. Open ( " mock " , " " )
156
+ db , err := sqlmock. New ( )
157
157
if err != nil {
158
158
t.Errorf (" An error '%s ' was not expected when opening a stub database connection" , err)
159
159
}
@@ -183,7 +183,7 @@ func TestShouldNotCancelOrderWithNonPendingStatus(t *testing.T) {
183
183
// will test order cancellation
184
184
func TestShouldRefundUserWhenOrderIsCancelled (t *testing .T ) {
185
185
// open database stub
186
- db , err := sql. Open ( " mock " , " " )
186
+ db , err := sqlmock. New ( )
187
187
if err != nil {
188
188
t.Errorf (" An error '%s ' was not expected when opening a stub database connection" , err)
189
189
}
@@ -221,7 +221,7 @@ func TestShouldRefundUserWhenOrderIsCancelled(t *testing.T) {
221
221
// will test order cancellation
222
222
func TestShouldRollbackOnError (t *testing .T ) {
223
223
// open database stub
224
- db , err := sql. Open ( " mock " , " " )
224
+ db , err := sqlmock. New ( )
225
225
if err != nil {
226
226
t.Errorf (" An error '%s ' was not expected when opening a stub database connection" , err)
227
227
}
@@ -320,6 +320,10 @@ Visit [godoc](http://godoc.org/github.com/DATA-DOG/go-sqlmock)
320
320
321
321
## Changes
322
322
323
+ - ** 2014-04-21** introduce ** sqlmock.New()** to open a mock database connection for tests. This method
324
+ calls sql.DB.Ping to ensure that connection is open, see [ issue] ( https://github.com/DATA-DOG/go-sqlmock/issues/4 ) .
325
+ This way on Close it will surely assert if all expectations are met, even if database was not triggered at all.
326
+ The old way is still available, but it is advisable to call db.Ping manually before asserting with db.Close.
323
327
- ** 2014-02-14** RowsFromCSVString is now a part of Rows interface named as FromCSVString.
324
328
It has changed to allow more ways to construct rows and to easily extend this API in future.
325
329
See [ issue 1] ( https://github.com/DATA-DOG/go-sqlmock/issues/1 )
0 commit comments