✨ Added sqltest testing util
This commit is contained in:
parent
e2f33be718
commit
757c06842c
|
@ -0,0 +1,28 @@
|
|||
package sqltest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
// Open creates a new InMemory sqlite3 database for testing.
|
||||
func Open(tb testing.TB) (*sqlx.DB, func()) {
|
||||
tb.Helper()
|
||||
|
||||
db, err := sqlx.Open("sqlite", ":memory:")
|
||||
require.NoError(tb, err)
|
||||
|
||||
if !assert.NoError(tb, db.Ping()) {
|
||||
_ = db.Close() //nolint: errcheck
|
||||
|
||||
tb.FailNow()
|
||||
}
|
||||
|
||||
return db, func() {
|
||||
_ = db.Close() //nolint: errcheck
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue