From a8170d4032c6afa175d887b414e6799f088f070c Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 23 Jul 2026 13:07:26 +0200 Subject: liturgy: fetch + HTML/JSON cache --- internal/liturgy/fetch_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 internal/liturgy/fetch_test.go (limited to 'internal/liturgy/fetch_test.go') diff --git a/internal/liturgy/fetch_test.go b/internal/liturgy/fetch_test.go new file mode 100644 index 0000000..ae8a68c --- /dev/null +++ b/internal/liturgy/fetch_test.go @@ -0,0 +1,32 @@ +package liturgy + +import ( + "net/http" + "net/http/httptest" + "os" + "testing" +) + +func TestLoadCaches(t *testing.T) { + html, _ := os.ReadFile("testdata/2026-06-22.html") + hits := 0 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + hits++ + w.Write(html) + })) + defer srv.Close() + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + baseURL = srv.URL + "/liturgia/%s/Ewangelia" // test hook + + secs1, err := Load(Options{Date: "2026-06-22"}) + if err != nil || len(secs1) == 0 { + t.Fatalf("load1: %v", err) + } + secs2, _ := Load(Options{Date: "2026-06-22"}) // should hit JSON cache + if hits != 1 { + t.Errorf("server hit %d times, want 1 (cache miss on repeat)", hits) + } + if len(secs2) != len(secs1) { + t.Error("cache returned different section count") + } +} -- cgit v1.3