summaryrefslogtreecommitdiff
path: root/internal/cli/cli_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/cli/cli_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/cli/cli_test.go')
-rw-r--r--internal/cli/cli_test.go120
1 files changed, 16 insertions, 104 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go
index 0e90a04..a244885 100644
--- a/internal/cli/cli_test.go
+++ b/internal/cli/cli_test.go
@@ -2,10 +2,6 @@ package cli
import (
"bytes"
- "net/http"
- "net/http/httptest"
- "os"
- "path/filepath"
"strings"
"testing"
@@ -65,8 +61,8 @@ func TestTwoDatesIsAmbiguous(t *testing.T) {
}
// TestUnknownVersion exercises -b/--bible's version-validation usage-error
-// path without touching the network: the version code is checked against
-// the five known codes before any fetch is attempted.
+// path: the version code is checked against the known corpus codes before
+// any reading is resolved.
func TestUnknownVersion(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
var out, errb bytes.Buffer
@@ -104,14 +100,6 @@ func TestLectionaryBogus(t *testing.T) {
}
}
-func TestLangBogus(t *testing.T) {
- t.Setenv("XDG_CONFIG_HOME", t.TempDir())
- var out, errb bytes.Buffer
- if code := Run([]string{"-g", "de"}, nil, &out, &errb); code != 2 {
- t.Errorf("bogus lang code=%d want 2 (stderr=%q)", code, errb.String())
- }
-}
-
// TestBannerForLang checks bannerFor's wording follows lang: pl reproduces
// the pre-i18n Polish banner exactly ("Ewangelia na D" / "Czytania na D"),
// en gives "Gospel for D" / "Readings for D".
@@ -133,71 +121,9 @@ func TestBannerForLang(t *testing.T) {
}
}
-// TestCleanEmptyCache exercises -C/--clean's dispatch as a maintenance mode:
-// it must be handled before any render path (and before the network-hitting
-// -u/--update path) is reached. Pointing XDG_CACHE_HOME at an empty temp dir
-// keeps liturgy.CleanCache's directory-read hermetic (no network), and an
-// empty dir exercises the "nothing to remove" branch of the summary line.
-func TestCleanEmptyCache(t *testing.T) {
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
- var out, errb bytes.Buffer
- code := Run([]string{"-C"}, nil, &out, &errb)
- if code != 0 {
- t.Fatalf("--clean code=%d want 0 (stderr=%q)", code, errb.String())
- }
- if !strings.Contains(out.String(), "clean") {
- t.Errorf("--clean stdout=%q, want a clean/nothing message", out.String())
- }
-}
-
-// TestCleanRemovesOldEntries exercises the non-empty summary branch: a stale
-// cache pair sitting in XDG_CACHE_HOME must be reported as removed, entirely
-// via the filesystem (no network involved).
-func TestCleanRemovesOldEntries(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)
- }
- if err := os.WriteFile(filepath.Join(cacheDir, "2020-01-01.html"), []byte("<html>old</html>"), 0o644); err != nil {
- t.Fatal(err)
- }
-
- var out, errb bytes.Buffer
- code := Run([]string{"--clean"}, nil, &out, &errb)
- if code != 0 {
- t.Fatalf("--clean code=%d want 0 (stderr=%q)", code, errb.String())
- }
- if !strings.Contains(out.String(), "cleaned 1 cache entry") {
- t.Errorf("--clean stdout=%q, want a \"cleaned 1 cache entry\" message", out.String())
- }
- if _, err := os.Stat(filepath.Join(cacheDir, "2020-01-01.html")); !os.IsNotExist(err) {
- t.Errorf("2020-01-01.html still exists after --clean")
- }
-}
-
-// TestCleanPreferredOverUpdate exercises Run's stated precedence: when both
-// --clean and -u/--update are given, --clean wins and -u's network-hitting
-// harvest path is never reached (proven here by the empty-cache dir plus a
-// zero exit code -- a network attempt against no test server would either
-// hang or return an error/non-zero code).
-func TestCleanPreferredOverUpdate(t *testing.T) {
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
- var out, errb bytes.Buffer
- code := Run([]string{"--clean", "-u"}, nil, &out, &errb)
- if code != 0 {
- t.Fatalf("--clean -u code=%d want 0 (stderr=%q)", code, errb.String())
- }
- if !strings.Contains(out.String(), "clean") {
- t.Errorf("--clean -u stdout=%q, want a clean/nothing message", out.String())
- }
-}
-
// TestDayInfoHeaderShown exercises fetchAndPrint's day-info header end to
-// end (via Run against a fixture server, matching internal/readings'
-// TestLoadModernRoutes): the day's celebration name appears above the
-// banner for the default (non-raw) render, and is entirely absent from
+// end (via Run, computed offline): the day's celebration name appears above
+// the banner for the default (non-raw) render, and is entirely absent from
// --raw output, which stays text-only for piping.
func TestDayInfoHeaderShown(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
@@ -381,15 +307,12 @@ func TestRandChapter(t *testing.T) {
}
}
-func TestRandBTFallsBack(t *testing.T) {
- // bt has no corpus but is accepted: --rand falls back to a corpus version
- // and still prints a passage (exit 0), rather than erroring.
+func TestRandRejectsBT(t *testing.T) {
+ // bt is no longer a valid version (its niedziela.pl corpus was retired), so
+ // --rand -b bt is a usage error, same as -p -b bt (see TestRefRejectsBT).
var out, errb bytes.Buffer
- if code := Run([]string{"--rand-v", "-b", "bt"}, nil, &out, &errb); code != 0 {
- t.Errorf("rand -b bt code=%d want 0 (stderr=%q)", code, errb.String())
- }
- if strings.TrimSpace(out.String()) == "" {
- t.Errorf("rand -b bt produced no output")
+ if code := Run([]string{"--rand-v", "-b", "bt"}, nil, &out, &errb); code != 2 {
+ t.Errorf("rand -b bt code=%d want 2 (stderr=%q)", code, errb.String())
}
}
@@ -423,15 +346,10 @@ func TestGospelCitationHelpers(t *testing.T) {
}
}
+// TestCitation exercises --citation end to end offline: the daily-readings
+// engine computes the day's gospel with no network/cache, and the reference is
+// printed in the configured sigla dialect.
func TestCitation(t *testing.T) {
- html, err := os.ReadFile("../liturgy/testdata/2026-07-22.html")
- if err != nil {
- t.Fatal(err)
- }
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write(html) }))
- defer srv.Close()
- liturgy.SetBaseURL(srv.URL + "/liturgia/%s/Ewangelia")
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
var out, errb bytes.Buffer
@@ -439,22 +357,16 @@ func TestCitation(t *testing.T) {
t.Fatalf("citation code=%d stderr=%q", code, errb.String())
}
// Default config resolves to the English dialect (sigla_style auto +
- // ui_language en), so the Polish source "J 20, 1. 11-18" is rendered as the
- // English sigla "Jn 20:1,11-18".
+ // ui_language en); 2026-07-22 is St Mary Magdalene, gospel John 20:1-2,11-18,
+ // rendered as the English sigla "Jn 20:...".
if s := strings.TrimSpace(out.String()); !strings.Contains(s, "Jn 20:") {
t.Errorf("citation = %q, want English-dialect gospel ref 'Jn 20:...'", s)
}
}
+// TestWeek exercises --week offline: seven days of gospel references starting
+// at the given date, one line each, computed by the offline engine.
func TestWeek(t *testing.T) {
- html, err := os.ReadFile("../liturgy/testdata/2026-07-22.html")
- if err != nil {
- t.Fatal(err)
- }
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write(html) }))
- defer srv.Close()
- liturgy.SetBaseURL(srv.URL + "/liturgia/%s/Ewangelia")
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
var out, errb bytes.Buffer