diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-24 09:15:40 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-24 09:15:40 +0200 |
| commit | b93de95dd24ff2a1d3126e6d7d00cd77530a03bf (patch) | |
| tree | 483a0901a20274152ba3f03f272f8098be4f49c0 /internal/readings | |
| parent | c1b954ad517cef00bf480d5229b253a8c6524be7 (diff) | |
| download | lectio-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')
| -rw-r--r-- | internal/readings/readings.go | 9 | ||||
| -rw-r--r-- | internal/readings/readings_test.go | 42 |
2 files changed, 42 insertions, 9 deletions
diff --git a/internal/readings/readings.go b/internal/readings/readings.go index 82d2fb9..ac7209a 100644 --- a/internal/readings/readings.go +++ b/internal/readings/readings.go @@ -5,7 +5,6 @@ package readings import ( - "fmt" "strings" "github.com/lukaszkasprzak/lectio/internal/config" @@ -21,7 +20,8 @@ type Options struct { // (modern lectionary only; see liturgy.Options.Refresh). Refresh bool // Offline restricts Load to previously cached/harvested data, never - // hitting the network. Traditional+Offline is not yet supported. + // hitting the network (both lectionaries; see liturgy.Options.Offline + // and tradlit.Load's offline parameter). Offline bool // All, when true, keeps every part the config doesn't explicitly hide; // when false, only the gospel is kept. @@ -38,10 +38,7 @@ func Load(cfg config.Config, opts Options) ([]liturgy.Section, error) { var err error if cfg.Lectionary == "traditional" { - if offline { - return nil, fmt.Errorf("readings: offline traditional not yet supported; use lectionary=new offline") - } - secs, err = tradlit.Load(opts.Date, cfg.TraditionalLang) + secs, err = tradlit.Load(opts.Date, cfg.TraditionalLang, offline) } else { secs, err = liturgy.Load(liturgy.Options{ Date: opts.Date, 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") } } |
