diff --git a/docker-compose.yml b/docker-compose.yml index c6b3c19accefe..c52bffe1dd759 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -57,10 +57,6 @@ services: ports: - "4150:4150" command: "/nsqd" - opcua: - image: open62541/open62541 - ports: - - "4840:4840" openldap: image: cobaugh/openldap-alpine environment: diff --git a/plugins/inputs/opcua/opcua_test.go b/plugins/inputs/opcua/opcua_test.go index c4a866f839570..fd082f23967c5 100644 --- a/plugins/inputs/opcua/opcua_test.go +++ b/plugins/inputs/opcua/opcua_test.go @@ -1,14 +1,12 @@ package opcua import ( - "context" "fmt" "reflect" "testing" "time" "github.com/stretchr/testify/require" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" "github.com/gopcua/opcua/ua" @@ -29,29 +27,17 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) { t.Skip("Skipping integration test in short mode") } - // Spin-up the container - ctx := context.Background() - req := testcontainers.GenericContainerRequest{ - ContainerRequest: testcontainers.ContainerRequest{ - Image: "open62541/open62541:1.0", - ExposedPorts: []string{"4840/tcp"}, - WaitingFor: wait.ForListeningPort("4840/tcp"), - }, - Started: true, + container := testutil.Container{ + Image: "open62541/open62541", + ExposedPorts: []string{"4840"}, + WaitingFor: wait.ForListeningPort("4840/tcp"), } - container, err := testcontainers.GenericContainer(ctx, req) - require.NoError(t, err, "starting container failed") + err := container.Start() + require.NoError(t, err, "failed to start container") defer func() { - require.NoError(t, container.Terminate(ctx), "terminating container failed") + require.NoError(t, container.Terminate(), "terminating container failed") }() - // Get the connection details from the container - addr, err := container.Host(ctx) - require.NoError(t, err, "getting container host address failed") - p, err := container.MappedPort(ctx, "4840/tcp") - require.NoError(t, err, "getting container host port failed") - port := p.Port() - var testopctags = []OPCTags{ {"ProductName", "1", "i", "2261", "open62541 OPC UA Server"}, {"ProductUri", "0", "i", "2262", "http://open62541.org"}, @@ -60,7 +46,7 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) { var o OpcUA o.MetricName = "testing" - o.Endpoint = fmt.Sprintf("opc.tcp://%s:%s", addr, port) + o.Endpoint = fmt.Sprintf("opc.tcp://%s:%s", container.Address, container.Port) fmt.Println(o.Endpoint) o.AuthMethod = "Anonymous" o.ConnectTimeout = config.Duration(10 * time.Second) @@ -94,6 +80,17 @@ func TestClient1Integration(t *testing.T) { t.Skip("Skipping integration test in short mode") } + container := testutil.Container{ + Image: "open62541/open62541", + ExposedPorts: []string{"4840"}, + WaitingFor: wait.ForListeningPort("4840/tcp"), + } + err := container.Start() + require.NoError(t, err, "failed to start container") + defer func() { + require.NoError(t, container.Terminate(), "terminating container failed") + }() + var testopctags = []OPCTags{ {"ProductName", "0", "i", "2261", "open62541 OPC UA Server"}, {"ProductUri", "0", "i", "2262", "http://open62541.org"}, @@ -103,10 +100,8 @@ func TestClient1Integration(t *testing.T) { } var o OpcUA - var err error - o.MetricName = "testing" - o.Endpoint = "opc.tcp://localhost:4840" + o.Endpoint = fmt.Sprintf("opc.tcp://%s:%s", container.Address, container.Port) o.AuthMethod = "Anonymous" o.ConnectTimeout = config.Duration(10 * time.Second) o.RequestTimeout = config.Duration(1 * time.Second)