-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
33 lines (29 loc) · 849 Bytes
/
Copy pathmain_test.go
File metadata and controls
33 lines (29 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"context"
"errors"
"fmt"
"testing"
"time"
)
func TestNewRedisLimiterReturnsWorkingLimiter(t *testing.T) {
limiterClient := newRedisLimiter("localhost:6379", 1, 1)
if limiterClient == nil {
t.Fatalf("expected limiter to be created")
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
decision, err := limiterClient.Decide(ctx, fmt.Sprintf("cmd-api-test-%d", time.Now().UnixNano()))
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
t.Skip("redis is not responding fast enough for the smoke test")
}
t.Fatalf("unexpected error from redis limiter: %v", err)
}
if decision.Backend != "redis" {
t.Fatalf("expected redis backend, got %+v", decision)
}
if !decision.Allowed {
t.Fatalf("expected first request to be allowed, got %+v", decision)
}
}