aboutsummaryrefslogtreecommitdiff
path: root/internal/liturgy/clean_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/liturgy/clean_test.go')
-rw-r--r--internal/liturgy/clean_test.go31
1 files changed, 17 insertions, 14 deletions
diff --git a/internal/liturgy/clean_test.go b/internal/liturgy/clean_test.go
index 4dbe0d9..d9ab4fc 100644
--- a/internal/liturgy/clean_test.go
+++ b/internal/liturgy/clean_test.go
@@ -7,12 +7,13 @@ import (
"time"
)
-// TestCleanCache exercises CleanCache's file-selection rules: only
-// "<YYYY-MM-DD>.html"/".json" pairs older than the cutoff are removed; a
-// recent pair and a non-matching file are left untouched. The cutoff is a
-// fixed literal (not time.Now-derived) so the test is deterministic; only
-// the "recent" fixture is anchored to today, and only to make sure it lands
-// safely on the "keep" side of that fixed cutoff.
+// TestCleanCache exercises CleanCache's file-selection rules: date-prefixed
+// cache files (modern ".html"/".json" and traditional ".trad.<lang>.json")
+// older than the cutoff are removed; recent files and a non-matching file
+// are left untouched. The cutoff is a fixed literal (not time.Now-derived)
+// so the test is deterministic; only the "recent" fixtures are anchored to
+// today, and only to make sure they land safely on the "keep" side of that
+// fixed cutoff.
func TestCleanCache(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CACHE_HOME", dir)
@@ -23,10 +24,12 @@ func TestCleanCache(t *testing.T) {
recent := time.Now().Format("2006-01-02")
files := map[string]string{
- "2020-01-01.html": "<html>old</html>",
- "2020-01-01.json": `[{"Heading":"old"}]`,
- recent + ".html": "<html>recent</html>",
- "notes.txt": "not a cache file",
+ "2020-01-01.html": "<html>old</html>",
+ "2020-01-01.json": `[{"Heading":"old"}]`,
+ "2020-01-01.trad.pl.json": `[{"info":{},"sections":[]}]`,
+ recent + ".html": "<html>recent</html>",
+ recent + ".trad.pl.json": `[{"info":{},"sections":[]}]`,
+ "notes.txt": "not a cache file",
}
for name, content := range files {
if err := os.WriteFile(filepath.Join(cacheDir, name), []byte(content), 0o644); err != nil {
@@ -39,19 +42,19 @@ func TestCleanCache(t *testing.T) {
if err != nil {
t.Fatalf("CleanCache: %v", err)
}
- if removed != 2 {
- t.Errorf("removed = %d, want 2", removed)
+ if removed != 3 {
+ t.Errorf("removed = %d, want 3", removed)
}
if freed <= 0 {
t.Errorf("freed = %d, want > 0", freed)
}
- for _, gone := range []string{"2020-01-01.html", "2020-01-01.json"} {
+ for _, gone := range []string{"2020-01-01.html", "2020-01-01.json", "2020-01-01.trad.pl.json"} {
if _, err := os.Stat(filepath.Join(cacheDir, gone)); !os.IsNotExist(err) {
t.Errorf("%s still exists after CleanCache, want removed", gone)
}
}
- for _, kept := range []string{recent + ".html", "notes.txt"} {
+ for _, kept := range []string{recent + ".html", recent + ".trad.pl.json", "notes.txt"} {
if _, err := os.Stat(filepath.Join(cacheDir, kept)); err != nil {
t.Errorf("%s missing after CleanCache, want kept: %v", kept, err)
}