test: migrate opcua to test-containers (#11171)
This commit is contained in:
parent
1c41f2d1ef
commit
d5ff34bc14
|
|
@ -50,10 +50,6 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "4150:4150"
|
- "4150:4150"
|
||||||
command: "/nsqd"
|
command: "/nsqd"
|
||||||
opcua:
|
|
||||||
image: open62541/open62541
|
|
||||||
ports:
|
|
||||||
- "4840:4840"
|
|
||||||
openldap:
|
openldap:
|
||||||
image: cobaugh/openldap-alpine
|
image: cobaugh/openldap-alpine
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
package opcua
|
package opcua
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/testcontainers/testcontainers-go"
|
|
||||||
"github.com/testcontainers/testcontainers-go/wait"
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
|
|
||||||
"github.com/gopcua/opcua/ua"
|
"github.com/gopcua/opcua/ua"
|
||||||
|
|
@ -29,29 +27,17 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) {
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spin-up the container
|
container := testutil.Container{
|
||||||
ctx := context.Background()
|
Image: "open62541/open62541",
|
||||||
req := testcontainers.GenericContainerRequest{
|
ExposedPorts: []string{"4840"},
|
||||||
ContainerRequest: testcontainers.ContainerRequest{
|
WaitingFor: wait.ForListeningPort("4840/tcp"),
|
||||||
Image: "open62541/open62541:1.0",
|
|
||||||
ExposedPorts: []string{"4840/tcp"},
|
|
||||||
WaitingFor: wait.ForListeningPort("4840/tcp"),
|
|
||||||
},
|
|
||||||
Started: true,
|
|
||||||
}
|
}
|
||||||
container, err := testcontainers.GenericContainer(ctx, req)
|
err := container.Start()
|
||||||
require.NoError(t, err, "starting container failed")
|
require.NoError(t, err, "failed to start container")
|
||||||
defer func() {
|
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{
|
var testopctags = []OPCTags{
|
||||||
{"ProductName", "1", "i", "2261", "open62541 OPC UA Server"},
|
{"ProductName", "1", "i", "2261", "open62541 OPC UA Server"},
|
||||||
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
|
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
|
||||||
|
|
@ -60,7 +46,7 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) {
|
||||||
|
|
||||||
var o OpcUA
|
var o OpcUA
|
||||||
o.MetricName = "testing"
|
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)
|
fmt.Println(o.Endpoint)
|
||||||
o.AuthMethod = "Anonymous"
|
o.AuthMethod = "Anonymous"
|
||||||
o.ConnectTimeout = config.Duration(10 * time.Second)
|
o.ConnectTimeout = config.Duration(10 * time.Second)
|
||||||
|
|
@ -94,6 +80,17 @@ func TestClient1Integration(t *testing.T) {
|
||||||
t.Skip("Skipping integration test in short mode")
|
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{
|
var testopctags = []OPCTags{
|
||||||
{"ProductName", "0", "i", "2261", "open62541 OPC UA Server"},
|
{"ProductName", "0", "i", "2261", "open62541 OPC UA Server"},
|
||||||
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
|
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
|
||||||
|
|
@ -103,10 +100,8 @@ func TestClient1Integration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var o OpcUA
|
var o OpcUA
|
||||||
var err error
|
|
||||||
|
|
||||||
o.MetricName = "testing"
|
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.AuthMethod = "Anonymous"
|
||||||
o.ConnectTimeout = config.Duration(10 * time.Second)
|
o.ConnectTimeout = config.Duration(10 * time.Second)
|
||||||
o.RequestTimeout = config.Duration(1 * time.Second)
|
o.RequestTimeout = config.Duration(1 * time.Second)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue