package web import "testing" func TestLimiterBurst(t *testing.T) { l := newLimiter(1, 2, 2, 2) ip := "203.0.113.10" if !l.Allow(ip, "general") || !l.Allow(ip, "general") { t.Fatal("burst was rejected") } if l.Allow(ip, "general") { t.Fatal("request over burst was allowed") } if !l.Allow(ip, "auth") || !l.Allow(ip, "auth") { t.Fatal("auth burst was rejected") } if l.Allow(ip, "auth") { t.Fatal("auth request over burst was allowed") } if !l.Allow("198.51.100.2", "general") { t.Fatal("different IP was limited") } }