时间选定库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
561 B

  1. package time_arrow
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func Test_cache_IsExpired(t *testing.T) {
  7. cachet := cache{}
  8. if cachet.IsExpired() {
  9. cachet.SetData("hello", time.Second*5)
  10. }
  11. time.Sleep(time.Second * 1)
  12. data := cachet.GetData()
  13. if cachet.IsExpired() {
  14. t.Error("cache should not be expired 1")
  15. }
  16. if data != "hello" {
  17. t.Error("cache should not be expired 2")
  18. }
  19. time.Sleep(time.Second * 5)
  20. data = cachet.GetData()
  21. if !cachet.IsExpired() {
  22. t.Error("cache should be expired 1 ")
  23. }
  24. if data != "" {
  25. t.Error("cache should be expired 2")
  26. }
  27. }