Skip to content

Commit

Permalink
Expose a RedisURL helper
Browse files Browse the repository at this point in the history
This is just so that if we a consumer of this package wants to control
the details of its own redis client for whatever reason, it doesn't have
to assume the name of the environment variable.
  • Loading branch information
nickstenning committed Oct 15, 2024
1 parent cb9b225 commit 5468067
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ func Context(t testing.TB) context.Context {
func Redis(ctx context.Context, t testing.TB) *redis.Client {
t.Helper()

redisURL := os.Getenv("REDIS_URL")
if redisURL == "" {
t.Skip("REDIS_URL is not set")
}

opts, err := redis.ParseURL(redisURL)
opts, err := redis.ParseURL(RedisURL(t))
if err != nil {
t.Fatalf("failed to parse redis url: %v", err)
}
Expand All @@ -42,6 +37,17 @@ func Redis(ctx context.Context, t testing.TB) *redis.Client {
return rdb
}

func RedisURL(t testing.TB) string {
t.Helper()

redisURL := os.Getenv("REDIS_URL")
if redisURL == "" {
t.Skip("REDIS_URL is not set")
}

return redisURL
}

func MiniRedis(t testing.TB) (*miniredis.Miniredis, *redis.Client) {
t.Helper()

Expand Down

0 comments on commit 5468067

Please sign in to comment.