diff options
Diffstat (limited to 'internal/liturgy/fetch_test.go')
| -rw-r--r-- | internal/liturgy/fetch_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
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") + } +} |
