feat: add cache layer over api

This commit is contained in:
2026-02-08 21:26:39 +00:00
parent 3a18041c6f
commit 1eab9909e8
4 changed files with 133 additions and 1 deletions
+43
View File
@@ -0,0 +1,43 @@
package geodata
import (
"os"
"testing"
)
func TestFetchLive(t *testing.T) {
tzMap, err := fetchLive()
if err != nil {
t.Fatal(err)
}
testTzMap(tzMap, t)
}
func TestCache(t *testing.T) {
// delete cache
cachePath := getCachePath()
if err := os.Remove(cachePath); err != nil && !os.IsNotExist(err) {
t.Fatal(err)
}
_, err := Fetch() // this populates cache
if err != nil {
t.Fatal(err)
}
tzMap, err := loadFromCache()
if err != nil {
t.Fatal(err)
}
testTzMap(tzMap, t)
}
func testTzMap(tzMap TimezoneMap, t *testing.T) {
entry0100 := tzMap["+0100"]
if len(entry0100) == 0 {
t.Fatalf("no countries found to timezone")
}
}