- Upgrade casbin from v2 to v3 across go.mod and pkg/auth/casbin.go - Add slide captcha verification to registration flow (CheckVerified, ConsumeVerified) - Add DB wrapper with connection pool statistics and health checks - Add Redis connection pool optimizations with stats and health monitoring - Add new config options: ConnMaxLifetime, HealthCheckInterval, EnableRetryOnError - Optimize slow query threshold from 200ms to 100ms - Add ping with retry mechanism for database and Redis connections
42 lines
905 B
Go
42 lines
905 B
Go
package database
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"go.uber.org/zap/zaptest"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// 使用内存 sqlite 验证 AutoMigrate 关键路径,无需真实 Postgres
|
|
func TestAutoMigrate_WithSQLite(t *testing.T) {
|
|
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
|
|
if err != nil {
|
|
t.Fatalf("open sqlite err: %v", err)
|
|
}
|
|
|
|
// 创建临时的 *DB 包装器用于测试
|
|
// 注意:这里不需要真正的连接池功能,只是测试 AutoMigrate
|
|
sqlDB, err := db.DB()
|
|
if err != nil {
|
|
t.Fatalf("get sql.DB err: %v", err)
|
|
}
|
|
|
|
tempDB := &DB{
|
|
DB: db,
|
|
sqlDB: sqlDB,
|
|
}
|
|
|
|
// 保存原始实例
|
|
originalDB := dbInstance
|
|
defer func() { dbInstance = originalDB }()
|
|
|
|
// 替换为测试实例
|
|
dbInstance = tempDB
|
|
|
|
logger := zaptest.NewLogger(t)
|
|
if err := AutoMigrate(logger); err != nil {
|
|
t.Fatalf("AutoMigrate sqlite err: %v", err)
|
|
}
|
|
}
|