You've already forked go-sqlxmock
mirror of
https://github.com/zhashkevych/go-sqlxmock.git
synced 2025-12-23 22:11:23 +02:00
added jmoiron/sqlx support
This commit is contained in:
30
sqlmock.go
30
sqlmock.go
@@ -14,6 +14,7 @@ import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -127,6 +128,35 @@ func (c *sqlmock) open(options []func(*sqlmock) error) (*sql.DB, Sqlmock, error)
|
||||
return db, c, db.Ping()
|
||||
}
|
||||
|
||||
func (c *sqlmock) openx(options []func(*sqlmock) error) (*sqlx.DB, Sqlmock, error) {
|
||||
db, err := sqlx.Open("sqlmock", c.dsn)
|
||||
if err != nil {
|
||||
return db, c, err
|
||||
}
|
||||
for _, option := range options {
|
||||
err := option(c)
|
||||
if err != nil {
|
||||
return db, c, err
|
||||
}
|
||||
}
|
||||
if c.converter == nil {
|
||||
c.converter = driver.DefaultParameterConverter
|
||||
}
|
||||
if c.queryMatcher == nil {
|
||||
c.queryMatcher = QueryMatcherRegexp
|
||||
}
|
||||
|
||||
if c.monitorPings {
|
||||
// We call Ping on the driver shortly to verify startup assertions by
|
||||
// driving internal behaviour of the sql standard library. We don't
|
||||
// want this call to ping to be monitored for expectation purposes so
|
||||
// temporarily disable.
|
||||
c.monitorPings = false
|
||||
defer func() { c.monitorPings = true }()
|
||||
}
|
||||
return db, c, db.Ping()
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectClose() *ExpectedClose {
|
||||
e := &ExpectedClose{}
|
||||
c.expected = append(c.expected, e)
|
||||
|
||||
Reference in New Issue
Block a user