diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-28 12:52:13 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-28 12:52:13 +0200 |
| commit | 44472bbe31475a3c672ae003d928d7caffb4b50a (patch) | |
| tree | e74bae03c61b62479ef4f68b046e3345618933c8 /internal/liturgy/clean_test.go | |
| parent | 626f2275438a37e5cd2efb5964281b9bef5ce8cc (diff) | |
| parent | 7b220084cf3951c8cde0582efdfcf628afc64336 (diff) | |
| download | lectio-44472bbe31475a3c672ae003d928d7caffb4b50a.tar.gz lectio-44472bbe31475a3c672ae003d928d7caffb4b50a.zip | |
Merge branch 'of-offline-migration': offline daily view, remove scrapers
Diffstat (limited to 'internal/liturgy/clean_test.go')
| -rw-r--r-- | internal/liturgy/clean_test.go | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/internal/liturgy/clean_test.go b/internal/liturgy/clean_test.go deleted file mode 100644 index d9ab4fc..0000000 --- a/internal/liturgy/clean_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package liturgy - -import ( - "os" - "path/filepath" - "testing" - "time" -) - -// 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) - cacheDir := filepath.Join(dir, "lectio") - if err := os.MkdirAll(cacheDir, 0o755); err != nil { - t.Fatal(err) - } - - recent := time.Now().Format("2006-01-02") - files := map[string]string{ - "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 { - t.Fatal(err) - } - } - - cutoff := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC) - removed, freed, err := CleanCache(cutoff) - if err != nil { - t.Fatalf("CleanCache: %v", err) - } - 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", "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", 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) - } - } -} - -// TestCleanCacheMissingDir checks the documented no-op: a cache dir that -// does not exist yet is not an error. -func TestCleanCacheMissingDir(t *testing.T) { - t.Setenv("XDG_CACHE_HOME", t.TempDir()) - removed, freed, err := CleanCache(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)) - if err != nil { - t.Fatalf("CleanCache on missing dir: %v", err) - } - if removed != 0 || freed != 0 { - t.Errorf("CleanCache on missing dir = (%d, %d), want (0, 0)", removed, freed) - } -} |
