Download this file
| 1 | package calls |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | func TestBudgetSlidesItsWindow(t *testing.T) { |
| 9 | b := newBudget(2, time.Minute) |
| 10 | now := time.Date(2026, 9, 8, 10, 0, 0, 0, time.UTC) |
| 11 | if !b.allow("k", now) || !b.allow("k", now) { |
| 12 | t.Fatal("first two refused") |
| 13 | } |
| 14 | if b.allow("k", now) { |
| 15 | t.Fatal("third allowed") |
| 16 | } |
| 17 | if !b.allow("other", now) { |
| 18 | t.Fatal("other key refused") |
| 19 | } |
| 20 | if !b.allow("k", now.Add(61*time.Second)) { |
| 21 | t.Fatal("refused after the window slid") |
| 22 | } |
| 23 | } |
| 24 | |