Skip to content

Commit

Permalink
net/redistest: update go-redis client to work with redis:6 (#2949)
Browse files Browse the repository at this point in the history
Update #2941 of go-redis to 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 updates go-redis to https://github.com/redis/go-redis/releases/tag/v9.5.1
and adds a test to verify it supports both redis:6 and redis:7

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
  • Loading branch information
AlexanderYastrebov authored Feb 20, 2024
1 parent da3d600 commit d4e9b79
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
24 changes: 19 additions & 5 deletions net/redistest/redistest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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},
Expand All @@ -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)
}

Expand Down
10 changes: 10 additions & 0 deletions net/redistest/redistest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit d4e9b79

Please sign in to comment.