periodic_traffic_reset_job_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. package job
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestMonthlyResetDue(t *testing.T) {
  7. cases := []struct {
  8. name string
  9. resetDay int
  10. now time.Time
  11. want bool
  12. }{
  13. {"legacy default on first", 0, time.Date(2026, time.July, 1, 0, 0, 0, 0, time.UTC), true},
  14. {"configured day", 15, time.Date(2026, time.July, 15, 0, 0, 0, 0, time.UTC), true},
  15. {"before configured day", 15, time.Date(2026, time.July, 14, 0, 0, 0, 0, time.UTC), false},
  16. {"month end", 31, time.Date(2026, time.January, 31, 0, 0, 0, 0, time.UTC), true},
  17. {"short month fallback", 31, time.Date(2026, time.February, 28, 0, 0, 0, 0, time.UTC), true},
  18. {"leap year fallback", 31, time.Date(2028, time.February, 29, 0, 0, 0, 0, time.UTC), true},
  19. {"not before short month end", 31, time.Date(2028, time.February, 28, 0, 0, 0, 0, time.UTC), false},
  20. }
  21. for _, tc := range cases {
  22. t.Run(tc.name, func(t *testing.T) {
  23. if got := monthlyResetDue(tc.resetDay, tc.now); got != tc.want {
  24. t.Fatalf("monthlyResetDue(%d, %s) = %v, want %v", tc.resetDay, tc.now.Format(time.DateOnly), got, tc.want)
  25. }
  26. })
  27. }
  28. }