mirror of
https://github.com/zhashkevych/go-sqlxmock.git
synced 2024-11-16 17:41:57 +02:00
move options to a separate file
This commit is contained in:
parent
3cbf32d5e7
commit
168056e96a
20
driver.go
20
driver.go
@ -35,8 +35,9 @@ func (d *mockDriver) Open(dsn string) (driver.Conn, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// New creates sqlmock database connection
|
||||
// and a mock to manage expectations.
|
||||
// New creates sqlmock database connection and a mock to manage expectations.
|
||||
// Accepts options, like ValueConverterOption, to use a ValueConverter from
|
||||
// a specific driver.
|
||||
// Pings db so that all expectations could be
|
||||
// asserted.
|
||||
func New(options ...func(*sqlmock) error) (*sql.DB, Sqlmock, error) {
|
||||
@ -51,8 +52,10 @@ func New(options ...func(*sqlmock) error) (*sql.DB, Sqlmock, error) {
|
||||
return smock.open(options)
|
||||
}
|
||||
|
||||
// NewWithDSN creates sqlmock database connection
|
||||
// with a specific DSN and a mock to manage expectations.
|
||||
// NewWithDSN creates sqlmock database connection with a specific DSN
|
||||
// and a mock to manage expectations.
|
||||
// Accepts options, like ValueConverterOption, to use a ValueConverter from
|
||||
// a specific driver.
|
||||
// Pings db so that all expectations could be asserted.
|
||||
//
|
||||
// This method is introduced because of sql abstraction
|
||||
@ -76,12 +79,3 @@ func NewWithDSN(dsn string, options ...func(*sqlmock) error) (*sql.DB, Sqlmock,
|
||||
|
||||
return smock.open(options)
|
||||
}
|
||||
|
||||
// WithValueConverter allows to create a sqlmock connection
|
||||
// with a custom ValueConverter to support drivers with special data types.
|
||||
func WithValueConverter(converter driver.ValueConverter) func(*sqlmock) error {
|
||||
return func(s *sqlmock) error {
|
||||
s.converter = converter
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func TestTwoOpenConnectionsOnTheSameDSN(t *testing.T) {
|
||||
|
||||
func TestWithOptions(t *testing.T) {
|
||||
c := &converter{}
|
||||
_, mock, err := New(WithValueConverter(c))
|
||||
_, mock, err := New(ValueConverterOption(c))
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, but got: %s", err)
|
||||
}
|
||||
|
12
options.go
Normal file
12
options.go
Normal file
@ -0,0 +1,12 @@
|
||||
package sqlmock
|
||||
|
||||
import "database/sql/driver"
|
||||
|
||||
// ValueConverterOption allows to create a sqlmock connection
|
||||
// with a custom ValueConverter to support drivers with special data types.
|
||||
func ValueConverterOption(converter driver.ValueConverter) func(*sqlmock) error {
|
||||
return func(s *sqlmock) error {
|
||||
s.converter = converter
|
||||
return nil
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user