forked from rudderlabs/rudder-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
53 lines (42 loc) · 1 KB
/
util_test.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package throttling
import (
"context"
"github.com/go-redis/redis/v8"
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/require"
"github.com/rudderlabs/rudder-server/testhelper/destination"
)
type tester interface {
Helper()
Log(...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...any)
FailNow()
Cleanup(f func())
}
type testCase struct {
rate,
window int64
}
func newLimiter(t tester, opts ...Option) *Limiter {
t.Helper()
l, err := New(opts...)
require.NoError(t, err)
return l
}
func bootstrapRedis(ctx context.Context, t tester, pool *dockertest.Pool) *redis.Client {
t.Helper()
redisContainer, err := destination.SetupRedis(ctx, pool, t)
require.NoError(t, err)
rc := redis.NewClient(&redis.Options{
Network: "tcp",
Addr: redisContainer.Addr,
})
t.Cleanup(func() { _ = rc.Close() })
pong, err := rc.Ping(ctx).Result()
if err != nil {
t.Fatalf("Could not ping Redis cluster: %v", err)
}
require.Equal(t, "PONG", pong)
return rc
}