时间选定库
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.

36 lines
629 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. t.Error("cache should be expired")
  10. }
  11. if cachet.IsExpired() {
  12. cachet.SetData("hello", time.Second*5)
  13. }
  14. time.Sleep(time.Second * 1)
  15. data := cachet.GetData()
  16. if cachet.IsExpired() {
  17. t.Error("cache should not be expired 1")
  18. }
  19. if data != "hello" {
  20. t.Error("cache should not be expired 2")
  21. }
  22. time.Sleep(time.Second * 5)
  23. data = cachet.GetData()
  24. if !cachet.IsExpired() {
  25. t.Error("cache should be expired 1 ")
  26. }
  27. if data != "" {
  28. t.Error("cache should be expired 2")
  29. }
  30. }