Enhance datastore DB test setup (#6450)

This commit is contained in:
6543
2026-04-15 23:55:06 +02:00
committed by GitHub
parent 9f901fc518
commit a025e4cff4
+7 -1
View File
@@ -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)