aboutsummaryrefslogtreecommitdiff
path: root/internal/tradlit/tradlit_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-28 12:50:31 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-28 12:50:31 +0200
commit7b220084cf3951c8cde0582efdfcf628afc64336 (patch)
treee74bae03c61b62479ef4f68b046e3345618933c8 /internal/tradlit/tradlit_test.go
parentfeede51697be870ae183a95b513ef64f031dbd0f (diff)
downloadlectio-7b220084cf3951c8cde0582efdfcf628afc64336.tar.gz
lectio-7b220084cf3951c8cde0582efdfcf628afc64336.zip
refactor: remove the niedziela/missalemeum scrapers, bt, traditional_lang
The daily view now computes entirely offline (previous commit), so retire the network path and everything that served it: - Delete internal/tradlit (missalemeum) and the niedziela scraper from internal/liturgy (fetch/store/parse + fixtures); keep Section, DayInfo and ExtractCitation. - Remove the "bt" version everywhere (render gatherBT + branches, config, i18n, web form, TUI) and bible.ToEnglishRef (Polish citation converter). A legacy config carrying "bt" migrates to "wuj" on load (config.migrateBT). - Remove the traditional_lang config field and the -g/--lang flag from all three binaries. - Drop the now-dead flags -R/--refresh, -o/--offline, -u/--update, -C/--clean and the harvest/clean commands. - New defaults: versions = wuj,vul,grb,drb; default_version = vul. Update the README (offline-by-design, no harvest/update), help text, and stale niedziela/bt doc comments. Tests updated for the offline reality; go test ./... and go vet ./... are clean, all three binaries build and run offline (OF + EF, compare, web).
Diffstat (limited to 'internal/tradlit/tradlit_test.go')
-rw-r--r--internal/tradlit/tradlit_test.go127
1 files changed, 0 insertions, 127 deletions
diff --git a/internal/tradlit/tradlit_test.go b/internal/tradlit/tradlit_test.go
deleted file mode 100644
index 8aa46eb..0000000
--- a/internal/tradlit/tradlit_test.go
+++ /dev/null
@@ -1,127 +0,0 @@
-package tradlit
-
-import (
- "net/http"
- "net/http/httptest"
- "os"
- "path/filepath"
- "strings"
- "testing"
-
- "github.com/lukaszkasprzak/lectio/internal/liturgy"
-)
-
-// TestLoadOnlineCachesRawBody exercises Load's online path: a successful
-// fetch is cached verbatim (the raw response body, not the parsed
-// sections) at tradlit's cache path, and parses the same way a cached read
-// would.
-func TestLoadOnlineCachesRawBody(t *testing.T) {
- body, err := os.ReadFile("testdata/2026-07-22.json")
- if err != nil {
- t.Fatal(err)
- }
- hits := 0
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- hits++
- w.Write(body)
- }))
- defer srv.Close()
-
- orig := baseURL
- baseURL = srv.URL + "/%s/api/v5/proper/%s"
- defer func() { baseURL = orig }()
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
-
- secs, info, err := Load("2026-07-22", "en", false)
- if err != nil {
- t.Fatalf("Load: %v", err)
- }
- if len(secs) == 0 {
- t.Fatal("Load returned no sections")
- }
- if info.Name != "St. Mary Magdalene" {
- t.Errorf("Load DayInfo.Name = %q, want %q", info.Name, "St. Mary Magdalene")
- }
- if hits != 1 {
- t.Errorf("server hit %d times, want 1", hits)
- }
-
- cached, err := os.ReadFile(filepath.Join(liturgy.CacheDir(), "2026-07-22.trad.en.json"))
- if err != nil {
- t.Fatalf("cache file not written: %v", err)
- }
- if string(cached) != string(body) {
- t.Error("cached content does not match the raw response body")
- }
-}
-
-// TestLoadOnline404WritesNoCache checks the documented invariant: a 404 (no
-// propers published for that date) returns an error and leaves the cache
-// directory untouched.
-func TestLoadOnline404WritesNoCache(t *testing.T) {
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(http.StatusNotFound)
- }))
- defer srv.Close()
-
- orig := baseURL
- baseURL = srv.URL + "/%s/api/v5/proper/%s"
- defer func() { baseURL = orig }()
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
-
- _, _, err := Load("2026-07-22", "en", false)
- if err == nil {
- t.Fatal("expected error on 404, got nil")
- }
-
- cachePath := filepath.Join(liturgy.CacheDir(), "2026-07-22.trad.en.json")
- if _, statErr := os.Stat(cachePath); !os.IsNotExist(statErr) {
- t.Errorf("cache file should not exist after a 404 (stat err = %v)", statErr)
- }
-}
-
-// TestLoadOfflineReadsCache exercises Load's offline path against a
-// pre-written cache file (as an earlier online Load, or 'lectio update',
-// would have left behind) -- no network access at all.
-func TestLoadOfflineReadsCache(t *testing.T) {
- body, err := os.ReadFile("testdata/2026-07-22.json")
- if err != nil {
- t.Fatal(err)
- }
- 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)
- }
- if err := os.WriteFile(filepath.Join(cacheDir, "2026-07-22.trad.pl.json"), body, 0o644); err != nil {
- t.Fatal(err)
- }
-
- secs, info, err := Load("2026-07-22", "pl", true)
- if err != nil {
- t.Fatalf("Load offline: %v", err)
- }
- if len(secs) == 0 {
- t.Fatal("Load offline returned no sections")
- }
- if info.Name != "St. Mary Magdalene" {
- t.Errorf("Load offline DayInfo.Name = %q, want %q", info.Name, "St. Mary Magdalene")
- }
-}
-
-// TestLoadOfflineMissingCacheErrors checks Load's offline path errors
-// clearly (mentioning the missing cache) rather than trying the network,
-// when nothing has been cached yet for that (date, lang).
-func TestLoadOfflineMissingCacheErrors(t *testing.T) {
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
-
- _, _, err := Load("2026-07-22", "pl", true)
- if err == nil {
- t.Fatal("expected error for missing cache, got nil")
- }
- msg := strings.ToLower(err.Error())
- if !strings.Contains(msg, "no cached") {
- t.Errorf("error %q should mention no cached propers", err.Error())
- }
-}