fix: usar fechas relativas en TestCleanOldLogs
Las fechas hardcoded (2026-02-24, 2026-03-01, 2026-03-06) quedaron fuera del periodo de retención de 7 días al avanzar el calendario. Ahora el test calcula las fechas relativas a time.Now() para que no caduque. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,18 +13,22 @@ func TestCleanOldLogs(t *testing.T) {
|
||||
agentDir := filepath.Join(dir, "bot1")
|
||||
os.MkdirAll(agentDir, 0o755)
|
||||
|
||||
// Create files: 10 days ago, 5 days ago, today.
|
||||
now := time.Now().UTC()
|
||||
oldDate := now.AddDate(0, 0, -10).Format("2006-01-02") // 10 days ago → should be removed
|
||||
recentDate := now.AddDate(0, 0, -5).Format("2006-01-02") // 5 days ago → should remain
|
||||
todayDate := now.Format("2006-01-02") // today → should remain
|
||||
|
||||
files := []string{
|
||||
"2026-02-24.jsonl",
|
||||
"2026-02-24.jsonl.gz",
|
||||
"2026-03-01.jsonl",
|
||||
"2026-03-06.jsonl",
|
||||
oldDate + ".jsonl",
|
||||
oldDate + ".jsonl.gz",
|
||||
recentDate + ".jsonl",
|
||||
todayDate + ".jsonl",
|
||||
}
|
||||
for _, f := range files {
|
||||
os.WriteFile(filepath.Join(agentDir, f), []byte("{}"), 0o644)
|
||||
}
|
||||
|
||||
// Retain 7 days → should remove 2026-02-24 files.
|
||||
// Retain 7 days → should remove files older than 7 days.
|
||||
cleanOldLogs(dir, "bot1", 7)
|
||||
|
||||
remaining, _ := os.ReadDir(agentDir)
|
||||
@@ -33,17 +37,17 @@ func TestCleanOldLogs(t *testing.T) {
|
||||
names[e.Name()] = true
|
||||
}
|
||||
|
||||
if names["2026-02-24.jsonl"] {
|
||||
t.Error("2026-02-24.jsonl should have been removed")
|
||||
if names[oldDate+".jsonl"] {
|
||||
t.Errorf("%s.jsonl should have been removed", oldDate)
|
||||
}
|
||||
if names["2026-02-24.jsonl.gz"] {
|
||||
t.Error("2026-02-24.jsonl.gz should have been removed")
|
||||
if names[oldDate+".jsonl.gz"] {
|
||||
t.Errorf("%s.jsonl.gz should have been removed", oldDate)
|
||||
}
|
||||
if !names["2026-03-01.jsonl"] {
|
||||
t.Error("2026-03-01.jsonl should still exist")
|
||||
if !names[recentDate+".jsonl"] {
|
||||
t.Errorf("%s.jsonl should still exist", recentDate)
|
||||
}
|
||||
if !names["2026-03-06.jsonl"] {
|
||||
t.Error("2026-03-06.jsonl should still exist")
|
||||
if !names[todayDate+".jsonl"] {
|
||||
t.Errorf("%s.jsonl should still exist", todayDate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user