refactor: align framework cleanup with new bootstrap flow
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
39
tests/testutils/helpers.go
Normal file
39
tests/testutils/helpers.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package testutils
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// SetupTestDBWithStore 设置测试数据库并返回 AccountStore 和 cleanup 函数
|
||||
// 用于需要 store 接口的集成测试
|
||||
func SetupTestDBWithStore(t *testing.T) (*gorm.DB, func()) {
|
||||
t.Helper()
|
||||
|
||||
db, redisClient := SetupTestDB(t)
|
||||
|
||||
cleanup := func() {
|
||||
TeardownTestDB(t, db, redisClient)
|
||||
}
|
||||
|
||||
return db, cleanup
|
||||
}
|
||||
|
||||
// GetMigrationsPath 获取数据库迁移文件的路径
|
||||
// 返回项目根目录下的 migrations 目录路径
|
||||
func GetMigrationsPath() string {
|
||||
// 获取当前文件路径
|
||||
_, filename, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
panic("无法获取当前文件路径")
|
||||
}
|
||||
|
||||
// 从 tests/testutils/helpers.go 向上两级到项目根目录
|
||||
projectRoot := filepath.Join(filepath.Dir(filename), "..", "..")
|
||||
migrationsPath := filepath.Join(projectRoot, "migrations")
|
||||
|
||||
return migrationsPath
|
||||
}
|
||||
Reference in New Issue
Block a user