diff options
Diffstat (limited to 'internal/readings/readings_test.go')
| -rw-r--r-- | internal/readings/readings_test.go | 42 |
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") } } |
