20 lines
395 B
Go
20 lines
395 B
Go
package httpserver
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRateLimiterRejectsAfterLimit(t *testing.T) {
|
|
limiter := newRateLimiter(2, time.Minute)
|
|
if !limiter.Allow("ip:path") {
|
|
t.Fatal("first attempt should be allowed")
|
|
}
|
|
if !limiter.Allow("ip:path") {
|
|
t.Fatal("second attempt should be allowed")
|
|
}
|
|
if limiter.Allow("ip:path") {
|
|
t.Fatal("third attempt should be rate limited")
|
|
}
|
|
}
|