From 5468067b21df75c71e81237a180a5b84ebeaed2f Mon Sep 17 00:00:00 2001 From: Nick Stenning Date: Tue, 15 Oct 2024 11:28:12 +0200 Subject: [PATCH] Expose a RedisURL helper 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. --- test/helpers.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/helpers.go b/test/helpers.go index 661c4f3..7a52411 100644 --- a/test/helpers.go +++ b/test/helpers.go @@ -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) } @@ -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()