重构: 按领域拆分大文件,清理死代码和空目录
app.go (768行) 拆分为 6 个文件: - app.go: App struct/辅助方法/NewApp/startup/shutdown/GetVersion - app_products.go: 商品加载/账号查询 - app_seckill.go: 抢购控制/日志/时间 - app_verify.go: 积分查询/兑换记录复验 - app_export.go: 账号导出/整理 - app_activity.go: 活动切换/配置保存 scheduler.go (1141行) 拆分为 4 个文件: - scheduler.go: struct/常量/设置/RunNow主循环/executeRound/辅助函数 - attempt.go: runAttempt/runAttemptFast/激进模式缓存 - warmup.go: 预热管理/warmupAttempts - schedule_timer.go: 定时抢购/时间校准/定时器管理 其他清理: - CollectFontCandidates 从 config 包移到 image 包(职责归属) - 删除 logger 死代码: ParseLogLine/ParseLogMeta/DetectLogLevel/ IsLogLevel/LogMeta/LogDebug/cutBracket 等反解析函数及对应测试 (日志结构化后不再有生产调用方) - 删除 static/ 空目录残留
This commit is contained in:
@@ -5,82 +5,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsLogLevel(t *testing.T) {
|
||||
valid := []string{"success", "error", "warn", "info", "debug", "SUCCESS", "Warn"}
|
||||
for _, l := range valid {
|
||||
if !IsLogLevel(l) {
|
||||
t.Errorf("IsLogLevel(%q) = false, want true", l)
|
||||
}
|
||||
}
|
||||
invalid := []string{"fatal", "trace", "", "warning"}
|
||||
for _, l := range invalid {
|
||||
if IsLogLevel(l) {
|
||||
t.Errorf("IsLogLevel(%q) = true, want false", l)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectLogLevel(t *testing.T) {
|
||||
cases := []struct {
|
||||
line string
|
||||
want string
|
||||
}{
|
||||
{"[2026/01/01 00:00:00.000][网络][debug] 调试", "debug"},
|
||||
{"[2026/01/01 00:00:00.000][抢购][success] 兑换成功", "success"},
|
||||
{"[2026/01/01 00:00:00.000][系统][error] 失败", "error"},
|
||||
{"[2026/01/01 00:00:00.000][系统][warn] 跳过", "warn"},
|
||||
{"[2026/01/01 00:00:00.000][系统][info] 信息", "info"},
|
||||
{"兑换成功完成", "success"},
|
||||
{"网络请求失败 error 发生", "error"},
|
||||
{"配置降级处理 warn", "warn"},
|
||||
{"普通信息日志", "info"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := DetectLogLevel(c.line); got != c.want {
|
||||
t.Errorf("DetectLogLevel(%q) = %q, want %q", c.line, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLogLine(t *testing.T) {
|
||||
line := "2026/01/01 12:00:00.123 [抢购][success] 账号:testuser 兑换成功"
|
||||
meta := ParseLogLine(line)
|
||||
if meta.Time != "2026-01-01 12:00:00.123" {
|
||||
t.Errorf("ParseLogLine Time = %q, want '2026-01-01 12:00:00.123'", meta.Time)
|
||||
}
|
||||
if meta.Category != "抢购" {
|
||||
t.Errorf("ParseLogLine Category = %q, want '抢购'", meta.Category)
|
||||
}
|
||||
if meta.Level != "success" {
|
||||
t.Errorf("ParseLogLine Level = %q, want 'success'", meta.Level)
|
||||
}
|
||||
if meta.Account != "testuser" {
|
||||
t.Errorf("ParseLogLine Account = %q, want 'testuser'", meta.Account)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLogLineShort(t *testing.T) {
|
||||
// 不含时间的行,ParseLogLine 不应 panic,Time 应为空
|
||||
line := "[系统][info] 配置已加载"
|
||||
meta := ParseLogLine(line)
|
||||
if meta.Category != "系统" {
|
||||
t.Errorf("ParseLogLine Category = %q, want '系统'", meta.Category)
|
||||
}
|
||||
if meta.Level != "info" {
|
||||
t.Errorf("ParseLogLine Level = %q, want 'info'", meta.Level)
|
||||
}
|
||||
if meta.Time != "" {
|
||||
t.Errorf("ParseLogLine Time = %q, want empty", meta.Time)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLogMeta(t *testing.T) {
|
||||
cat, lvl := ParseLogMeta("[网络][warn] 降级")
|
||||
if cat != "网络" || lvl != "warn" {
|
||||
t.Errorf("ParseLogMeta = (%q, %q), want ('网络', 'warn')", cat, lvl)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStructuredLogging 验证 LogEvent→sink→MemoryLogStore 结构化链路:
|
||||
// LogEntry 的 category/level/account 应直接由调用方填入,而非字符串反解析。
|
||||
func TestStructuredLogging(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user