mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-09-05 20:07:25 +00:00
Enhance datastore DB test setup (#6450)
This commit is contained in:
@@ -38,10 +38,16 @@ func testDriverConfig() (driver, config string) {
|
||||
// newTestStore creates a new database connection for testing purposes.
|
||||
// The database driver and connection string are provided by
|
||||
// environment variables, with fallback to in-memory sqlite.
|
||||
func newTestStore(t *testing.T, tables ...any) (*storage, func()) {
|
||||
func newTestStore(t *testing.T, tables ...any) (store *storage, closer func()) {
|
||||
engine, err := xorm.NewEngine(testDriverConfig())
|
||||
require.NoError(t, err)
|
||||
|
||||
// MaxOpenConns=1 and MaxIdleConns=1 are required for in-memory sqlite:
|
||||
// without them the pool drops idle connections, destroying the in-memory
|
||||
// schema between calls and breaking migrations.
|
||||
engine.SetMaxOpenConns(1)
|
||||
engine.SetMaxIdleConns(1)
|
||||
|
||||
for _, table := range tables {
|
||||
if err := engine.Sync(table); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user