test: migrate opcua to test-containers (#11171)
This commit is contained in:
parent
1c41f2d1ef
commit
d5ff34bc14
|
|
@ -50,10 +50,6 @@ services:
|
|||
ports:
|
||||
- "4150:4150"
|
||||
command: "/nsqd"
|
||||
opcua:
|
||||
image: open62541/open62541
|
||||
ports:
|
||||
- "4840:4840"
|
||||
openldap:
|
||||
image: cobaugh/openldap-alpine
|
||||
environment:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue