Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
40 lines
904 B
Go
40 lines
904 B
Go
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
|
|
}
|