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") } }