From 88f1a3b9a6d3edbd4f9b088553cdb5d03c8c98d7 Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Tue, 20 Feb 2024 18:20:53 +0100 Subject: [PATCH] net/redistest: update go-redis client to work with redis:6 Update https://github.com/redis/go-redis/releases/tag/v9.5.0 broke support of redis:6 Unfortunately we did not catch it because we updated test redis to redis:7 recently, see #2895 This change adds test to verify client supports both redis:6 and redis:7 Signed-off-by: Alexander Yastrebov --- go.mod | 2 +- go.sum | 4 ++-- net/redistest/redistest.go | 24 +++++++++++++++++++----- net/redistest/redistest_test.go | 10 ++++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 0f13c3dbd4..73bf3efd14 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/opentracing/opentracing-go v1.2.0 github.com/prometheus/client_golang v1.18.0 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 - github.com/redis/go-redis/v9 v9.5.0 + github.com/redis/go-redis/v9 v9.5.1 github.com/sarslanhan/cronmask v0.0.0-20230801193303-54e29300a091 github.com/sirupsen/logrus v1.9.3 github.com/sony/gobreaker v0.5.0 diff --git a/go.sum b/go.sum index 6846fc2d80..40fda341ab 100644 --- a/go.sum +++ b/go.sum @@ -351,8 +351,8 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/redis/go-redis/v9 v9.5.0 h1:Xe9TKMmZv939gwTBcvc0n1tzK5l2re0pKw/W/tN3amw= -github.com/redis/go-redis/v9 v9.5.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8= +github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= diff --git a/net/redistest/redistest.go b/net/redistest/redistest.go index e731e7b827..5e01298e42 100644 --- a/net/redistest/redistest.go +++ b/net/redistest/redistest.go @@ -12,14 +12,23 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) +type options struct { + password string + image string +} + func NewTestRedis(t testing.TB) (address string, done func()) { - return NewTestRedisWithPassword(t, "") + return newTestRedisWithOptions(t, options{}) } func NewTestRedisWithPassword(t testing.TB, password string) (address string, done func()) { + return newTestRedisWithOptions(t, options{password: password}) +} + +func newTestRedisWithOptions(t testing.TB, opts options) (address string, done func()) { var args []string - if password != "" { - args = append(args, "--requirepass", password) + if opts.password != "" { + args = append(args, "--requirepass", opts.password) } start := time.Now() @@ -38,9 +47,14 @@ func NewTestRedisWithPassword(t testing.TB, password string) (address string, do t.Fatalf("Failed to get new nat port: %v", err) } + image := "redis:7-alpine" + if opts.image != "" { + image = opts.image + } + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "redis:7-alpine", + Image: image, Cmd: args, ExposedPorts: []string{"6379/tcp"}, Networks: []string{network.Name}, @@ -66,7 +80,7 @@ func NewTestRedisWithPassword(t testing.TB, password string) (address string, do t.Logf("Started redis server at %s in %v", address, time.Since(start)) - if err := ping(ctx, address, password); err != nil { + if err := ping(ctx, address, opts.password); err != nil { t.Fatalf("Failed to ping redis server: %v", err) } diff --git a/net/redistest/redistest_test.go b/net/redistest/redistest_test.go index 94c6f4dba9..0fa295e7bf 100644 --- a/net/redistest/redistest_test.go +++ b/net/redistest/redistest_test.go @@ -15,3 +15,13 @@ func TestRedistest(t *testing.T) { t.Fatalf("Failed to ping redis: %v", err) } } + +func TestRedistestRedis6(t *testing.T) { + r, done := newTestRedisWithOptions(t, options{image: "redis:6-alpine"}) + defer done() + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + if err := ping(ctx, r, ""); err != nil { + t.Fatalf("Failed to ping redis: %v", err) + } +}