cleaner_test.go 894 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package cache
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestNextDelay(t *testing.T) {
  8. tests := []struct {
  9. name string
  10. input time.Duration
  11. output time.Duration
  12. ok bool
  13. }{
  14. {
  15. name: "second",
  16. input: time.Second,
  17. output: time.Second * 5,
  18. ok: true,
  19. },
  20. {
  21. name: "5 seconds",
  22. input: time.Second * 5,
  23. output: time.Minute,
  24. ok: true,
  25. },
  26. {
  27. name: "minute",
  28. input: time.Minute,
  29. output: time.Minute * 5,
  30. ok: true,
  31. },
  32. {
  33. name: "5 minutes",
  34. input: time.Minute * 5,
  35. output: time.Hour,
  36. ok: true,
  37. },
  38. {
  39. name: "hour",
  40. input: time.Hour,
  41. output: 0,
  42. ok: false,
  43. },
  44. }
  45. for _, test := range tests {
  46. t.Run(test.name, func(t *testing.T) {
  47. next, ok := nextDelay(test.input)
  48. assert.Equal(t, test.ok, ok)
  49. assert.Equal(t, test.output, next)
  50. })
  51. }
  52. }