@@ -2,19 +2,17 @@ package ratelimiter_test
22
33import (
44 "context"
5- "fmt"
65 "log"
7- "strings"
86 "testing"
97 "time"
108
119 redis "github.com/redis/go-redis/v9"
10+ "github.com/qor5/x/v3/gormx"
11+ "github.com/qor5/x/v3/redisx"
1212 "github.com/stretchr/testify/require"
13- testredis "github.com/testcontainers/testcontainers-go/modules/redis"
1413 "github.com/theplant/ratelimiter"
1514 "github.com/theplant/ratelimiter/redisrl"
1615 "github.com/theplant/ratelimiter/sqlrl"
17- "github.com/qor5/x/v3/gormx"
1816 "gorm.io/gorm"
1917)
2018
@@ -33,25 +31,15 @@ func TestMain(m *testing.M) {
3331 }
3432 }()
3533
36- redisContainer , err := testredis .Run (ctx , "redis:7-alpine" )
37- if err != nil {
38- panic (fmt .Errorf ("failed to start redis container: %w" , err ))
39- }
34+ redisTestSuite := redisx .MustStartTestSuite (ctx )
4035 defer func () {
41- if err := redisContainer . Terminate (context .Background ()); err != nil {
42- log .Fatalf ("Failed to terminate redis container : %v" , err )
36+ if err := redisTestSuite . Stop (context .Background ()); err != nil {
37+ log .Fatalf ("Failed to stop redis test suite : %v" , err )
4338 }
4439 }()
4540
46- endpoint , err := redisContainer .ConnectionString (ctx )
47- if err != nil {
48- panic (fmt .Errorf ("failed to get redis connection string: %w" , err ))
49- }
50-
5141 db = testSuite .DB ()
52- redisCli = redis .NewClient (& redis.Options {
53- Addr : strings .TrimPrefix (endpoint , "redis://" ),
54- })
42+ redisCli = redisTestSuite .Client ()
5543 defer redisCli .Close ()
5644
5745 // Create SQL rate limiter and migrate table
0 commit comments