Skip to content

Commit

Permalink
test: migrate redis to test-containers (#11174)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored May 24, 2022
1 parent dd8dd75 commit cb9d9fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ services:
ports:
- "15672:15672"
- "5672:5672"
redis:
image: redis:alpine
ports:
- "6379:6379"
nsq:
image: nsqio/nsq
ports:
Expand Down
16 changes: 14 additions & 2 deletions plugins/inputs/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/go-redis/redis"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/influxdata/telegraf/testutil"
)
Expand All @@ -33,7 +34,18 @@ func TestRedisConnectIntegration(t *testing.T) {
t.Skip("Skipping integration test in short mode")
}

addr := fmt.Sprintf(testutil.GetLocalHost() + ":6379")
container := testutil.Container{
Image: "redis:alpine",
ExposedPorts: []string{"6379"},
WaitingFor: wait.ForListeningPort("6379/tcp"),
}
err := container.Start()
require.NoError(t, err, "failed to start container")
defer func() {
require.NoError(t, container.Terminate(), "terminating container failed")
}()

addr := fmt.Sprintf("%s:%s", container.Address, container.Port)

r := &Redis{
Log: testutil.Logger{},
Expand All @@ -42,7 +54,7 @@ func TestRedisConnectIntegration(t *testing.T) {

var acc testutil.Accumulator

err := acc.GatherError(r.Gather)
err = acc.GatherError(r.Gather)
require.NoError(t, err)
}

Expand Down
16 changes: 14 additions & 2 deletions plugins/inputs/redis_sentinel/redis_sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/testutil"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/stretchr/testify/require"
)
Expand All @@ -21,15 +22,26 @@ func TestRedisSentinelConnect(t *testing.T) {
t.Skip("Skipping integration test in short mode")
}

addr := fmt.Sprintf("tcp://" + testutil.GetLocalHost() + ":26379")
container := testutil.Container{
Image: "redis:alpine",
ExposedPorts: []string{"6379"},
WaitingFor: wait.ForListeningPort("6379/tcp"),
}
err := container.Start()
require.NoError(t, err, "failed to start container")
defer func() {
require.NoError(t, container.Terminate(), "terminating container failed")
}()

addr := fmt.Sprintf("tcp://%s:%s", container.Address, container.Port)

r := &RedisSentinel{
Servers: []string{addr},
}

var acc testutil.Accumulator

err := acc.GatherError(r.Gather)
err = acc.GatherError(r.Gather)
require.NoError(t, err)
}

Expand Down

0 comments on commit cb9d9fe

Please sign in to comment.