golimiter_test.go 356 B

12345678910111213141516171819202122
  1. package golimiter
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestTokenBucket(t *testing.T) {
  7. tb := NewTokenBucket(10, 5, time.Second)
  8. for i := 0; i < 10; i++ {
  9. if !tb.TakeToken() {
  10. t.Errorf("Expected token %d, but bucket is empty", i)
  11. }
  12. }
  13. if tb.TakeToken() {
  14. t.Errorf("Expected bucket to be empty, but token was taken")
  15. }
  16. }