test: migrate redis to test-containers (#11174)
This commit is contained in:
parent
dd8dd75824
commit
cb9d9fe075
|
|
@ -56,10 +56,6 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "15672:15672"
|
- "15672:15672"
|
||||||
- "5672:5672"
|
- "5672:5672"
|
||||||
redis:
|
|
||||||
image: redis:alpine
|
|
||||||
ports:
|
|
||||||
- "6379:6379"
|
|
||||||
nsq:
|
nsq:
|
||||||
image: nsqio/nsq
|
image: nsqio/nsq
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
@ -33,7 +34,18 @@ func TestRedisConnectIntegration(t *testing.T) {
|
||||||
t.Skip("Skipping integration test in short mode")
|
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{
|
r := &Redis{
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
|
|
@ -42,7 +54,7 @@ func TestRedisConnectIntegration(t *testing.T) {
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
err := acc.GatherError(r.Gather)
|
err = acc.GatherError(r.Gather)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
@ -21,7 +22,18 @@ func TestRedisSentinelConnect(t *testing.T) {
|
||||||
t.Skip("Skipping integration test in short mode")
|
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{
|
r := &RedisSentinel{
|
||||||
Servers: []string{addr},
|
Servers: []string{addr},
|
||||||
|
|
@ -29,7 +41,7 @@ func TestRedisSentinelConnect(t *testing.T) {
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
err := acc.GatherError(r.Gather)
|
err = acc.GatherError(r.Gather)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue