feat: 实现门店套餐分配功能并统一测试基础设施
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m30s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m30s
新增功能: - 门店套餐分配管理(shop_package_allocation):支持门店套餐库存管理 - 门店套餐系列分配管理(shop_series_allocation):支持套餐系列分配和佣金层级设置 - 我的套餐查询(my_package):支持门店查询自己的套餐分配情况 测试改进: - 统一集成测试基础设施,新增 testutils.NewIntegrationTestEnv - 重构所有集成测试使用新的测试环境设置 - 移除旧的测试辅助函数和冗余测试文件 - 新增 test_helpers_test.go 统一任务测试辅助 技术细节: - 新增数据库迁移 000025_create_shop_allocation_tables - 新增 3 个 Handler、Service、Store 和对应的单元测试 - 更新 OpenAPI 文档和文档生成器 - 测试覆盖率:Service 层 > 90% Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -390,13 +390,10 @@ func TestMiddlewareOrder(t *testing.T) {
|
||||
t.Logf("Middleware execution order: %v", executionOrder)
|
||||
}
|
||||
|
||||
// TestLoggerMiddlewareWithUserID 测试 Logger 中间件记录用户 ID(T044)
|
||||
func TestLoggerMiddlewareWithUserID(t *testing.T) {
|
||||
// 创建临时目录用于日志
|
||||
tempDir := t.TempDir()
|
||||
accessLogFile := filepath.Join(tempDir, "access-userid.log")
|
||||
|
||||
// 初始化日志系统
|
||||
err := logger.InitLoggers("info", false,
|
||||
logger.LogRotationConfig{
|
||||
Filename: filepath.Join(tempDir, "app.log"),
|
||||
@@ -418,19 +415,16 @@ func TestLoggerMiddlewareWithUserID(t *testing.T) {
|
||||
}
|
||||
defer func() { _ = logger.Sync() }()
|
||||
|
||||
// 创建应用
|
||||
app := fiber.New()
|
||||
|
||||
// 注册中间件
|
||||
app.Use(requestid.New(requestid.Config{
|
||||
Generator: func() string {
|
||||
return uuid.NewString()
|
||||
},
|
||||
}))
|
||||
|
||||
// 模拟 auth 中间件设置 user_id
|
||||
app.Use(func(c *fiber.Ctx) error {
|
||||
c.Locals(constants.ContextKeyUserID, "user_12345")
|
||||
c.Locals(constants.ContextKeyUserID, uint(12345))
|
||||
return c.Next()
|
||||
})
|
||||
|
||||
@@ -440,7 +434,6 @@ func TestLoggerMiddlewareWithUserID(t *testing.T) {
|
||||
return c.SendString("ok")
|
||||
})
|
||||
|
||||
// 执行请求
|
||||
req := httptest.NewRequest("GET", "/test", nil)
|
||||
resp, err := app.Test(req)
|
||||
if err != nil {
|
||||
@@ -448,19 +441,17 @@ func TestLoggerMiddlewareWithUserID(t *testing.T) {
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
// 刷新日志缓冲区
|
||||
_ = logger.Sync()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// 验证访问日志包含 user_id
|
||||
content, err := os.ReadFile(accessLogFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to read access log: %v", err)
|
||||
}
|
||||
|
||||
logContent := string(content)
|
||||
if !strings.Contains(logContent, "user_12345") {
|
||||
t.Error("Access log should contain user_id 'user_12345'")
|
||||
if !strings.Contains(logContent, "12345") {
|
||||
t.Error("Access log should contain user_id '12345'")
|
||||
}
|
||||
|
||||
t.Logf("Access log with user_id:\n%s", logContent)
|
||||
|
||||
Reference in New Issue
Block a user