diff --git a/cache_test.go b/cache_test.go new file mode 100644 index 0000000..1dd2252 --- /dev/null +++ b/cache_test.go @@ -0,0 +1,31 @@ +package time_arrow + +import ( + "testing" + "time" +) + +func Test_cache_IsExpired(t *testing.T) { + cachet := cache{} + if cachet.IsExpired() { + cachet.SetData("hello", time.Second*5) + } + + time.Sleep(time.Second * 1) + data := cachet.GetData() + if cachet.IsExpired() { + t.Error("cache should not be expired 1") + } + if data != "hello" { + t.Error("cache should not be expired 2") + } + + time.Sleep(time.Second * 5) + data = cachet.GetData() + if !cachet.IsExpired() { + t.Error("cache should be expired 1 ") + } + if data != "" { + t.Error("cache should be expired 2") + } +} diff --git a/core.go b/core.go index 2374be7..22687aa 100644 --- a/core.go +++ b/core.go @@ -392,6 +392,9 @@ func GetHolidaysDataWithCache() ([]HolidaysItem, error) { data := holidayCache.GetData() var result []HolidaysItem err := json.Unmarshal([]byte(data), &result) + if len(data) == 0 { + panic("GetHolidaysDataWithCache json unmarshal error") + } return result, err }