test: migrate nats to test-containers (#11170)
This commit is contained in:
parent
94ad7f1bfa
commit
03034cd1d1
|
|
@ -73,10 +73,6 @@ services:
|
||||||
image: open62541/open62541
|
image: open62541/open62541
|
||||||
ports:
|
ports:
|
||||||
- "4840:4840"
|
- "4840:4840"
|
||||||
nats:
|
|
||||||
image: nats
|
|
||||||
ports:
|
|
||||||
- "4222:4222"
|
|
||||||
openldap:
|
openldap:
|
||||||
image: cobaugh/openldap-alpine
|
image: cobaugh/openldap-alpine
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package nats
|
package nats
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/plugins/serializers"
|
"github.com/influxdata/telegraf/plugins/serializers"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConnectAndWriteIntegration(t *testing.T) {
|
func TestConnectAndWriteIntegration(t *testing.T) {
|
||||||
|
|
@ -13,7 +15,18 @@ func TestConnectAndWriteIntegration(t *testing.T) {
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
server := []string{"nats://" + testutil.GetLocalHost() + ":4222"}
|
container := testutil.Container{
|
||||||
|
Image: "nats",
|
||||||
|
ExposedPorts: []string{"4222"},
|
||||||
|
WaitingFor: wait.ForLog("Server is ready"),
|
||||||
|
}
|
||||||
|
err := container.Start()
|
||||||
|
require.NoError(t, err, "failed to start container")
|
||||||
|
defer func() {
|
||||||
|
require.NoError(t, container.Terminate(), "terminating container failed")
|
||||||
|
}()
|
||||||
|
|
||||||
|
server := []string{fmt.Sprintf("nats://%s:%s", container.Address, container.Port)}
|
||||||
s, _ := serializers.NewInfluxSerializer()
|
s, _ := serializers.NewInfluxSerializer()
|
||||||
n := &NATS{
|
n := &NATS{
|
||||||
Servers: server,
|
Servers: server,
|
||||||
|
|
@ -23,7 +36,7 @@ func TestConnectAndWriteIntegration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that we can connect to the NATS daemon
|
// Verify that we can connect to the NATS daemon
|
||||||
err := n.Connect()
|
err = n.Connect()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Verify that we can successfully write data to the NATS daemon
|
// Verify that we can successfully write data to the NATS daemon
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue