All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 15s
- 创建全局单例连接池,性能提升 6-7 倍 - 实现 NewTestTransaction/GetTestRedis/CleanTestRedisKeys - 移除旧的 SetupTestDB/TeardownTestDB API - 迁移所有测试文件到新方案(47 个文件) - 添加测试连接管理规范文档 - 更新 AGENTS.md 和 README.md 性能对比: - 旧方案:~71 秒(204 测试) - 新方案:~10.5 秒(首次初始化 + 后续复用) - 内存占用降低约 80% - 网络连接数从 204 降至 1
27 lines
523 B
Go
27 lines
523 B
Go
package testutils
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// GenerateUsername 生成测试用户名
|
|
func GenerateUsername(prefix string, index int) string {
|
|
return fmt.Sprintf("%s_%d", prefix, index)
|
|
}
|
|
|
|
// GeneratePhone 生成测试手机号
|
|
func GeneratePhone(prefix string, index int) string {
|
|
return fmt.Sprintf("%s%08d", prefix, index)
|
|
}
|
|
|
|
// Now 返回当前时间
|
|
func Now() time.Time {
|
|
return time.Now()
|
|
}
|
|
|
|
// Since 返回从指定时间到现在的持续时间
|
|
func Since(t time.Time) time.Duration {
|
|
return time.Since(t)
|
|
}
|