aboutsummaryrefslogtreecommitdiff
path: root/internal/liturgy/fetch_test.go
blob: ae8a68cf0fabd936966d0414e478101c85ca3e32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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")
	}
}