You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zk/adapter/sqlite/transaction_test.go

35 lines
787 B
Go

package sqlite
import (
"testing"
"github.com/go-testfixtures/testfixtures/v3"
"github.com/mickael-menu/zk/util/test/assert"
)
// testTransaction is an utility function used to test a SQLite transaction to
// the DB.
func testTransaction(t *testing.T, test func(tx Transaction)) {
db, err := OpenInMemory()
assert.Nil(t, err)
err = db.Migrate()
assert.Nil(t, err)
fixtures, err := testfixtures.New(
testfixtures.Database(db.db),
testfixtures.Dialect("sqlite"),
testfixtures.Directory("fixtures"),
// Necessary to work with an in-memory database.
testfixtures.DangerousSkipTestDatabaseCheck(),
)
assert.Nil(t, err)
err = fixtures.Load()
assert.Nil(t, err)
err = db.WithTransaction(func(tx Transaction) error {
test(tx)
return nil
})
assert.Nil(t, err)
}