mirror of
https://github.com/asticode/go-astikit.git
synced 2025-12-24 11:50:53 +08:00
27 lines
409 B
Go
27 lines
409 B
Go
package astikit
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLimiter(t *testing.T) {
|
|
var l = NewLimiter()
|
|
defer l.Close()
|
|
l.Add("test", 2, time.Second)
|
|
b, ok := l.Bucket("test")
|
|
if !ok {
|
|
t.Fatal("no bucket found")
|
|
}
|
|
defer b.Close()
|
|
if !b.Inc() {
|
|
t.Fatalf("got false, expected true")
|
|
}
|
|
if !b.Inc() {
|
|
t.Fatalf("got false, expected true")
|
|
}
|
|
if b.Inc() {
|
|
t.Fatalf("got true, expected false")
|
|
}
|
|
}
|