Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/redistest: update go-redis client to work with redis:6
Browse files Browse the repository at this point in the history
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 <alexander.yastrebov@zalando.de>
AlexanderYastrebov committed Feb 20, 2024
1 parent da3d600 commit 88f1a3b
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
@@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
24 changes: 19 additions & 5 deletions net/redistest/redistest.go
Original file line number Diff line number Diff line change
@@ -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)
}

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

Please sign in to comment.