aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/cli_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-28 12:52:13 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-28 12:52:13 +0200
commit44472bbe31475a3c672ae003d928d7caffb4b50a (patch)
treee74bae03c61b62479ef4f68b046e3345618933c8 /internal/cli/cli_test.go
parent626f2275438a37e5cd2efb5964281b9bef5ce8cc (diff)
parent7b220084cf3951c8cde0582efdfcf628afc64336 (diff)
downloadlectio-44472bbe31475a3c672ae003d928d7caffb4b50a.tar.gz
lectio-44472bbe31475a3c672ae003d928d7caffb4b50a.zip
Merge branch 'of-offline-migration': offline daily view, remove scrapers
Diffstat (limited to 'internal/cli/cli_test.go')
-rw-r--r--internal/cli/cli_test.go136
1 files changed, 20 insertions, 116 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go
index b08ffba..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,90 +121,20 @@ 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) {
- 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())
+ const name = "Saint Mary Magdalene" // universal sanctoral, authored in English
+
var out, errb bytes.Buffer
if code := Run([]string{"2026-07-22"}, nil, &out, &errb); code != 0 {
t.Fatalf("Run code=%d stderr=%q", code, errb.String())
}
- if !strings.Contains(out.String(), "Święto św. Marii Magdaleny") {
+ if !strings.Contains(out.String(), name) {
t.Errorf("stdout missing day-info header: %q", out.String())
}
@@ -225,7 +143,7 @@ func TestDayInfoHeaderShown(t *testing.T) {
if code := Run([]string{"2026-07-22", "-r"}, nil, &out, &errb); code != 0 {
t.Fatalf("Run --raw code=%d stderr=%q", code, errb.String())
}
- if strings.Contains(out.String(), "Święto św. Marii Magdaleny") {
+ if strings.Contains(out.String(), name) {
t.Errorf("--raw stdout should omit the day-info header: %q", out.String())
}
}
@@ -389,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())
}
}
@@ -431,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
@@ -447,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