Documentation
¶
Overview ¶
package sqlhelptest contains helper functions for testing database functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Driver = "postgres"
Driver that will be emulated for the mock db.
Functions ¶
func InitMockDB ¶
InitMockDB returns a sqlx.DB and sqlmock.Sqlmock for testing. On cleanup, it will check if all expectations were met. Your t.Run may look like this:
t.Run("Test", func(t *testing.T) {
db, mock := InitMockDB(t)
expectFn(mock)
// test your function
})
With the expectFn being a function that sets up the expectations for the mock (of type ExpectFunc), add it to your tests struct like so:
tests := []struct {
name string
fields fields
args args
expectFn sqlhelptest.ExpectFunc
want int64
wantErr bool
} //...
Types ¶
type ExpectFunc ¶
ExpectFunc is a function that sets up the expectations for the mock.
Click to show internal directories.
Click to hide internal directories.