mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-16 07:33:06 +08:00
22 lines
568 B
Go
22 lines
568 B
Go
package testutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/repository"
|
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
|
"github.com/alicebob/miniredis/v2"
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
// NewRedisGatewayCache returns a real Redis-backed gateway cache for tests.
|
|
func NewRedisGatewayCache(t *testing.T) service.GatewayCache {
|
|
t.Helper()
|
|
|
|
redisServer := miniredis.RunT(t)
|
|
redisClient := redis.NewClient(&redis.Options{Addr: redisServer.Addr()})
|
|
t.Cleanup(func() { _ = redisClient.Close() })
|
|
|
|
return repository.NewGatewayCache(redisClient)
|
|
}
|