summaryrefslogtreecommitdiff
path: root/internal/readings/readings_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 09:15:40 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 09:15:40 +0200
commitb93de95dd24ff2a1d3126e6d7d00cd77530a03bf (patch)
tree483a0901a20274152ba3f03f272f8098be4f49c0 /internal/readings/readings_test.go
parentc1b954ad517cef00bf480d5229b253a8c6524be7 (diff)
downloadlectio-b93de95dd24ff2a1d3126e6d7d00cd77530a03bf.tar.gz
lectio-b93de95dd24ff2a1d3126e6d7d00cd77530a03bf.zip
tradlit: offline caching + read; update pre-caches traditional; --clean prunes it; v0.2.0
Diffstat (limited to 'internal/readings/readings_test.go')
-rw-r--r--internal/readings/readings_test.go42
1 files changed, 39 insertions, 3 deletions
diff --git a/internal/readings/readings_test.go b/internal/readings/readings_test.go
index 20df5e0..9a31802 100644
--- a/internal/readings/readings_test.go
+++ b/internal/readings/readings_test.go
@@ -4,6 +4,7 @@ import (
"net/http"
"net/http/httptest"
"os"
+ "path/filepath"
"strings"
"testing"
@@ -107,14 +108,49 @@ func TestLoadModernRoutes(t *testing.T) {
}
}
-func TestLoadTraditionalOfflineErrors(t *testing.T) {
+// TestLoadTraditionalOfflineErrorsWithoutCache exercises the (formerly
+// unsupported) traditional+offline path when nothing has been cached yet
+// for that date/lang: it must fail clearly rather than silently falling
+// back to the network or to the modern lectionary's sigla store.
+func TestLoadTraditionalOfflineErrorsWithoutCache(t *testing.T) {
+ t.Setenv("XDG_CACHE_HOME", t.TempDir())
+
cfg := config.Config{Lectionary: "traditional", TraditionalLang: "pl"}
_, err := Load(cfg, Options{Date: "2026-07-22", Offline: true})
if err == nil {
t.Fatal("expected error, got nil")
}
msg := strings.ToLower(err.Error())
- if !strings.Contains(msg, "offline") || !strings.Contains(msg, "traditional") {
- t.Errorf("error %q should mention offline and traditional", err.Error())
+ if !strings.Contains(msg, "no cached") {
+ t.Errorf("error %q should mention no cached propers", err.Error())
+ }
+}
+
+// TestLoadTraditionalOfflineReadsCache is the positive counterpart: once a
+// prior online Load (or 'lectio update') has cached a date's traditional
+// propers, Load(offline=true) must serve them from disk, no network
+// involved.
+func TestLoadTraditionalOfflineReadsCache(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)
+ }
+ body, err := os.ReadFile("../tradlit/testdata/2026-07-22.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(cacheDir, "2026-07-22.trad.pl.json"), body, 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ cfg := config.Config{Lectionary: "traditional", TraditionalLang: "pl"}
+ secs, err := Load(cfg, Options{Date: "2026-07-22", Offline: true, All: true})
+ if err != nil {
+ t.Fatalf("Load: %v", err)
+ }
+ if len(secs) == 0 {
+ t.Error("expected traditional offline sections, got none")
}
}