Add visitor phone lookup flow
This commit is contained in:
26
server/internal/httpapi/limiter_test.go
Normal file
26
server/internal/httpapi/limiter_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestQueryLimiterResetsAfterWindow(t *testing.T) {
|
||||
now := time.Unix(100, 0)
|
||||
limiter := newQueryLimiter(func() time.Time { return now }, 2, time.Minute)
|
||||
|
||||
if allowed, _ := limiter.allow("phone:test"); !allowed {
|
||||
t.Fatal("first query should be allowed")
|
||||
}
|
||||
if allowed, _ := limiter.allow("phone:test"); !allowed {
|
||||
t.Fatal("second query should be allowed")
|
||||
}
|
||||
if allowed, retry := limiter.allow("phone:test"); allowed || retry <= 0 {
|
||||
t.Fatalf("third query should be limited with a retry duration, got allowed=%v retry=%s", allowed, retry)
|
||||
}
|
||||
|
||||
now = now.Add(time.Minute)
|
||||
if allowed, _ := limiter.allow("phone:test"); !allowed {
|
||||
t.Fatal("query should be allowed after the window resets")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user