2022-04-12 05:32:25 +08:00
|
|
|
package opcua
|
2020-09-03 06:52:46 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"reflect"
|
|
|
|
|
"testing"
|
2020-09-04 11:48:00 +08:00
|
|
|
"time"
|
|
|
|
|
|
2022-05-28 00:24:31 +08:00
|
|
|
"github.com/docker/go-connections/nat"
|
2021-11-02 22:42:22 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-02-08 04:20:12 +08:00
|
|
|
"github.com/testcontainers/testcontainers-go/wait"
|
2021-11-02 22:42:22 +08:00
|
|
|
|
2022-01-12 06:39:18 +08:00
|
|
|
"github.com/gopcua/opcua/ua"
|
2020-09-04 11:48:00 +08:00
|
|
|
"github.com/influxdata/telegraf/config"
|
2021-07-31 04:26:47 +08:00
|
|
|
"github.com/influxdata/telegraf/testutil"
|
2020-09-03 06:52:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type OPCTags struct {
|
|
|
|
|
Name string
|
|
|
|
|
Namespace string
|
|
|
|
|
IdentifierType string
|
|
|
|
|
Identifier string
|
2021-07-31 04:26:47 +08:00
|
|
|
Want interface{}
|
2020-09-03 06:52:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-28 00:24:31 +08:00
|
|
|
const servicePort = "4840"
|
|
|
|
|
|
2022-02-08 04:20:12 +08:00
|
|
|
func TestGetDataBadNodeContainerIntegration(t *testing.T) {
|
|
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 00:05:04 +08:00
|
|
|
container := testutil.Container{
|
|
|
|
|
Image: "open62541/open62541",
|
2022-05-28 00:24:31 +08:00
|
|
|
ExposedPorts: []string{servicePort},
|
|
|
|
|
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)),
|
2022-02-08 04:20:12 +08:00
|
|
|
}
|
2022-05-25 00:05:04 +08:00
|
|
|
err := container.Start()
|
|
|
|
|
require.NoError(t, err, "failed to start container")
|
2022-02-08 04:20:12 +08:00
|
|
|
defer func() {
|
2022-05-25 00:05:04 +08:00
|
|
|
require.NoError(t, container.Terminate(), "terminating container failed")
|
2022-02-08 04:20:12 +08:00
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
var testopctags = []OPCTags{
|
|
|
|
|
{"ProductName", "1", "i", "2261", "open62541 OPC UA Server"},
|
|
|
|
|
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
|
|
|
|
|
{"ManufacturerName", "0", "i", "2263", "open62541"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var o OpcUA
|
|
|
|
|
o.MetricName = "testing"
|
2022-05-28 00:24:31 +08:00
|
|
|
o.Endpoint = fmt.Sprintf("opc.tcp://%s:%s", container.Address, container.Ports[servicePort])
|
2022-02-08 04:20:12 +08:00
|
|
|
fmt.Println(o.Endpoint)
|
|
|
|
|
o.AuthMethod = "Anonymous"
|
|
|
|
|
o.ConnectTimeout = config.Duration(10 * time.Second)
|
|
|
|
|
o.RequestTimeout = config.Duration(1 * time.Second)
|
|
|
|
|
o.SecurityPolicy = "None"
|
|
|
|
|
o.SecurityMode = "None"
|
|
|
|
|
o.codes = []ua.StatusCode{ua.StatusOK}
|
|
|
|
|
logger := &testutil.CaptureLogger{}
|
|
|
|
|
o.Log = logger
|
|
|
|
|
|
|
|
|
|
g := GroupSettings{
|
|
|
|
|
MetricName: "anodic_current",
|
|
|
|
|
TagsSlice: [][]string{
|
|
|
|
|
{"pot", "2002"},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tags := range testopctags {
|
|
|
|
|
g.Nodes = append(g.Nodes, MapOPCTag(tags))
|
|
|
|
|
}
|
|
|
|
|
o.Groups = append(o.Groups, g)
|
|
|
|
|
err = o.Init()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
err = Connect(&o)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Contains(t, logger.LastError, "E! [] status not OK for node 'ProductName'(metric name 'anodic_current', tags 'pot=2002')")
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 02:06:12 +08:00
|
|
|
func TestClient1Integration(t *testing.T) {
|
2021-04-10 02:23:32 +08:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
|
}
|
2020-09-04 11:48:00 +08:00
|
|
|
|
2022-05-25 00:05:04 +08:00
|
|
|
container := testutil.Container{
|
|
|
|
|
Image: "open62541/open62541",
|
2022-05-28 00:24:31 +08:00
|
|
|
ExposedPorts: []string{servicePort},
|
|
|
|
|
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)),
|
2022-05-25 00:05:04 +08:00
|
|
|
}
|
|
|
|
|
err := container.Start()
|
|
|
|
|
require.NoError(t, err, "failed to start container")
|
|
|
|
|
defer func() {
|
|
|
|
|
require.NoError(t, container.Terminate(), "terminating container failed")
|
|
|
|
|
}()
|
|
|
|
|
|
2020-09-03 06:52:46 +08:00
|
|
|
var testopctags = []OPCTags{
|
2020-12-03 08:06:47 +08:00
|
|
|
{"ProductName", "0", "i", "2261", "open62541 OPC UA Server"},
|
|
|
|
|
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
|
|
|
|
|
{"ManufacturerName", "0", "i", "2263", "open62541"},
|
2021-07-31 04:26:47 +08:00
|
|
|
{"badnode", "1", "i", "1337", nil},
|
|
|
|
|
{"goodnode", "1", "s", "the.answer", "42"},
|
2020-09-03 06:52:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var o OpcUA
|
2020-12-03 08:06:47 +08:00
|
|
|
o.MetricName = "testing"
|
2022-05-28 00:24:31 +08:00
|
|
|
o.Endpoint = fmt.Sprintf("opc.tcp://%s:%s", container.Address, container.Ports[servicePort])
|
2020-09-04 11:48:00 +08:00
|
|
|
o.AuthMethod = "Anonymous"
|
|
|
|
|
o.ConnectTimeout = config.Duration(10 * time.Second)
|
|
|
|
|
o.RequestTimeout = config.Duration(1 * time.Second)
|
2020-09-03 06:52:46 +08:00
|
|
|
o.SecurityPolicy = "None"
|
|
|
|
|
o.SecurityMode = "None"
|
2022-01-12 06:39:18 +08:00
|
|
|
o.codes = []ua.StatusCode{ua.StatusOK}
|
2021-07-31 04:26:47 +08:00
|
|
|
o.Log = testutil.Logger{}
|
2020-09-03 06:52:46 +08:00
|
|
|
for _, tags := range testopctags {
|
2020-12-03 08:06:47 +08:00
|
|
|
o.RootNodes = append(o.RootNodes, MapOPCTag(tags))
|
2020-09-03 06:52:46 +08:00
|
|
|
}
|
|
|
|
|
err = o.Init()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("Initialize Error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
err = Connect(&o)
|
|
|
|
|
if err != nil {
|
2020-09-04 11:48:00 +08:00
|
|
|
t.Fatalf("Connect Error: %s", err)
|
2020-09-03 06:52:46 +08:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 08:06:47 +08:00
|
|
|
for i, v := range o.nodeData {
|
2020-09-03 06:52:46 +08:00
|
|
|
if v.Value != nil {
|
|
|
|
|
types := reflect.TypeOf(v.Value)
|
|
|
|
|
value := reflect.ValueOf(v.Value)
|
|
|
|
|
compare := fmt.Sprintf("%v", value.Interface())
|
|
|
|
|
if compare != testopctags[i].Want {
|
2020-12-03 08:06:47 +08:00
|
|
|
t.Errorf("Tag %s: Values %v for type %s does not match record", o.nodes[i].tag.FieldName, value.Interface(), types)
|
2020-09-03 06:52:46 +08:00
|
|
|
}
|
2021-07-31 04:26:47 +08:00
|
|
|
} else if testopctags[i].Want != nil {
|
2020-12-03 08:06:47 +08:00
|
|
|
t.Errorf("Tag: %s has value: %v", o.nodes[i].tag.FieldName, v.Value)
|
2020-09-03 06:52:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
2022-09-27 01:33:59 +08:00
|
|
|
|
2022-09-28 00:39:37 +08:00
|
|
|
// test unregistered reads workaround
|
|
|
|
|
o.Workarounds.UseUnregisteredReads = true
|
2022-09-27 01:33:59 +08:00
|
|
|
|
|
|
|
|
for i := range o.nodeData {
|
|
|
|
|
o.nodeData[i] = OPCData{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = Connect(&o)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Connect Error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i, v := range o.nodeData {
|
|
|
|
|
if v.Value != nil {
|
|
|
|
|
types := reflect.TypeOf(v.Value)
|
|
|
|
|
value := reflect.ValueOf(v.Value)
|
|
|
|
|
compare := fmt.Sprintf("%v", value.Interface())
|
|
|
|
|
if compare != testopctags[i].Want {
|
|
|
|
|
t.Errorf("Tag %s: Values %v for type %s does not match record", o.nodes[i].tag.FieldName, value.Interface(), types)
|
|
|
|
|
}
|
|
|
|
|
} else if testopctags[i].Want != nil {
|
|
|
|
|
t.Errorf("Tag: %s has value: %v", o.nodes[i].tag.FieldName, v.Value)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 06:52:46 +08:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 08:06:47 +08:00
|
|
|
func MapOPCTag(tags OPCTags) (out NodeSettings) {
|
|
|
|
|
out.FieldName = tags.Name
|
2020-09-03 06:52:46 +08:00
|
|
|
out.Namespace = tags.Namespace
|
|
|
|
|
out.IdentifierType = tags.IdentifierType
|
|
|
|
|
out.Identifier = tags.Identifier
|
|
|
|
|
return out
|
|
|
|
|
}
|
2020-09-04 11:48:00 +08:00
|
|
|
|
|
|
|
|
func TestConfig(t *testing.T) {
|
|
|
|
|
toml := `
|
|
|
|
|
[[inputs.opcua]]
|
|
|
|
|
name = "localhost"
|
|
|
|
|
endpoint = "opc.tcp://localhost:4840"
|
|
|
|
|
connect_timeout = "10s"
|
|
|
|
|
request_timeout = "5s"
|
|
|
|
|
security_policy = "auto"
|
|
|
|
|
security_mode = "auto"
|
|
|
|
|
certificate = "/etc/telegraf/cert.pem"
|
|
|
|
|
private_key = "/etc/telegraf/key.pem"
|
|
|
|
|
auth_method = "Anonymous"
|
|
|
|
|
username = ""
|
|
|
|
|
password = ""
|
|
|
|
|
nodes = [
|
2022-10-13 00:41:44 +08:00
|
|
|
{name="name", namespace="1", identifier_type="s", identifier="one", tags=[["tag0", "val0"]]},
|
|
|
|
|
{name="name2", namespace="2", identifier_type="s", identifier="two", tags=[["tag0", "val0"], ["tag00", "val00"]]},
|
2020-09-04 11:48:00 +08:00
|
|
|
]
|
2020-12-03 08:06:47 +08:00
|
|
|
[[inputs.opcua.group]]
|
|
|
|
|
name = "foo"
|
|
|
|
|
namespace = "3"
|
|
|
|
|
identifier_type = "i"
|
|
|
|
|
tags = [["tag1", "val1"], ["tag2", "val2"]]
|
|
|
|
|
nodes = [{name="name3", identifier="3000", tags=[["tag3", "val3"]]}]
|
|
|
|
|
[[inputs.opcua.group]]
|
|
|
|
|
name = "bar"
|
|
|
|
|
namespace = "0"
|
|
|
|
|
identifier_type = "i"
|
|
|
|
|
tags = [["tag1", "val1"], ["tag2", "val2"]]
|
|
|
|
|
nodes = [{name="name4", identifier="4000", tags=[["tag1", "override"]]}]
|
2022-01-12 06:39:18 +08:00
|
|
|
|
|
|
|
|
[inputs.opcua.workarounds]
|
|
|
|
|
additional_valid_status_codes = ["0xC0"]
|
2020-09-04 11:48:00 +08:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
c := config.NewConfig()
|
|
|
|
|
err := c.LoadConfigData([]byte(toml))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
require.Len(t, c.Inputs, 1)
|
|
|
|
|
|
|
|
|
|
o, ok := c.Inputs[0].Input.(*OpcUA)
|
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
2020-12-03 08:06:47 +08:00
|
|
|
require.Len(t, o.RootNodes, 2)
|
|
|
|
|
require.Equal(t, o.RootNodes[0].FieldName, "name")
|
|
|
|
|
require.Equal(t, o.RootNodes[1].FieldName, "name2")
|
|
|
|
|
|
|
|
|
|
require.Len(t, o.Groups, 2)
|
|
|
|
|
require.Equal(t, o.Groups[0].MetricName, "foo")
|
|
|
|
|
require.Len(t, o.Groups[0].Nodes, 1)
|
|
|
|
|
require.Equal(t, o.Groups[0].Nodes[0].Identifier, "3000")
|
|
|
|
|
|
|
|
|
|
require.NoError(t, o.InitNodes())
|
|
|
|
|
require.Len(t, o.nodes, 4)
|
2022-10-13 00:41:44 +08:00
|
|
|
require.Len(t, o.nodes[0].metricTags, 1)
|
|
|
|
|
require.Len(t, o.nodes[1].metricTags, 2)
|
2020-12-03 08:06:47 +08:00
|
|
|
require.Len(t, o.nodes[2].metricTags, 3)
|
|
|
|
|
require.Len(t, o.nodes[3].metricTags, 2)
|
2022-01-12 06:39:18 +08:00
|
|
|
|
|
|
|
|
require.Len(t, o.Workarounds.AdditionalValidStatusCodes, 1)
|
|
|
|
|
require.Equal(t, o.Workarounds.AdditionalValidStatusCodes[0], "0xC0")
|
2020-12-03 08:06:47 +08:00
|
|
|
}
|
|
|
|
|
|
2022-07-28 03:14:01 +08:00
|
|
|
func TestConfigWithMismatchedTypes(t *testing.T) {
|
|
|
|
|
toml := `
|
|
|
|
|
[[inputs.opcua]]
|
|
|
|
|
name = "localhost"
|
|
|
|
|
endpoint = "opc.tcp://localhost:4840"
|
|
|
|
|
connect_timeout = "10s"
|
|
|
|
|
request_timeout = "5s"
|
|
|
|
|
security_policy = "auto"
|
|
|
|
|
security_mode = "auto"
|
|
|
|
|
certificate = "/etc/telegraf/cert.pem"
|
|
|
|
|
private_key = "/etc/telegraf/key.pem"
|
|
|
|
|
auth_method = "Anonymous"
|
|
|
|
|
username = ""
|
|
|
|
|
password = ""
|
|
|
|
|
nodes = [
|
|
|
|
|
{name="name", namespace="1", identifier_type="s", identifier="one"},
|
|
|
|
|
{name="name2", namespace="2", identifier_type="i", identifier="two"},
|
|
|
|
|
]
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
c := config.NewConfig()
|
|
|
|
|
err := c.LoadConfigData([]byte(toml))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
require.Len(t, c.Inputs, 1)
|
|
|
|
|
|
|
|
|
|
o, ok := c.Inputs[0].Input.(*OpcUA)
|
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
|
|
require.Len(t, o.RootNodes, 2)
|
|
|
|
|
require.Equal(t, o.RootNodes[0].FieldName, "name")
|
|
|
|
|
require.Equal(t, o.RootNodes[1].FieldName, "name2")
|
|
|
|
|
|
|
|
|
|
require.Error(t, o.InitNodes())
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-03 08:06:47 +08:00
|
|
|
func TestTagsSliceToMap(t *testing.T) {
|
|
|
|
|
m, err := tagsSliceToMap([][]string{{"foo", "bar"}, {"baz", "bat"}})
|
2021-11-02 22:42:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Len(t, m, 2)
|
|
|
|
|
require.Equal(t, m["foo"], "bar")
|
|
|
|
|
require.Equal(t, m["baz"], "bat")
|
2020-12-03 08:06:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTagsSliceToMap_twoStrings(t *testing.T) {
|
|
|
|
|
var err error
|
|
|
|
|
_, err = tagsSliceToMap([][]string{{"foo", "bar", "baz"}})
|
2021-11-02 22:42:22 +08:00
|
|
|
require.Error(t, err)
|
2020-12-03 08:06:47 +08:00
|
|
|
_, err = tagsSliceToMap([][]string{{"foo"}})
|
2021-11-02 22:42:22 +08:00
|
|
|
require.Error(t, err)
|
2020-12-03 08:06:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTagsSliceToMap_dupeKey(t *testing.T) {
|
|
|
|
|
_, err := tagsSliceToMap([][]string{{"foo", "bar"}, {"foo", "bat"}})
|
2021-11-02 22:42:22 +08:00
|
|
|
require.Error(t, err)
|
2020-12-03 08:06:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTagsSliceToMap_empty(t *testing.T) {
|
|
|
|
|
_, err := tagsSliceToMap([][]string{{"foo", ""}})
|
2021-11-02 22:42:22 +08:00
|
|
|
require.Equal(t, fmt.Errorf("tag 1 has empty value"), err)
|
2020-12-03 08:06:47 +08:00
|
|
|
_, err = tagsSliceToMap([][]string{{"", "bar"}})
|
2021-11-02 22:42:22 +08:00
|
|
|
require.Equal(t, fmt.Errorf("tag 1 has empty name"), err)
|
2020-12-03 08:06:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestValidateOPCTags(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
nodes []Node
|
|
|
|
|
err error
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
"same",
|
|
|
|
|
[]Node{
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "v1", "t2": "v2"},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "v1", "t2": "v2"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
fmt.Errorf("name 'fn' is duplicated (metric name 'mn', tags 't1=v1, t2=v2')"),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"different metric tag names",
|
|
|
|
|
[]Node{
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "", "t2": ""},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "", "t3": ""},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
nil,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"different metric tag values",
|
|
|
|
|
[]Node{
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "foo", "t2": ""},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "bar", "t2": ""},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
nil,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"different metric names",
|
|
|
|
|
[]Node{
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "", "t2": ""},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn2",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "", "t2": ""},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
nil,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"different field names",
|
|
|
|
|
[]Node{
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "", "t2": ""},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
metricName: "mn",
|
|
|
|
|
tag: NodeSettings{FieldName: "fn2", IdentifierType: "s"},
|
|
|
|
|
metricTags: map[string]string{"t1": "", "t2": ""},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
nil,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
o := OpcUA{
|
|
|
|
|
nodes: tt.nodes,
|
2021-07-31 04:26:47 +08:00
|
|
|
Log: testutil.Logger{},
|
2020-12-03 08:06:47 +08:00
|
|
|
}
|
|
|
|
|
require.Equal(t, tt.err, o.validateOPCTags())
|
|
|
|
|
})
|
|
|
|
|
}
|
2020-09-04 11:48:00 +08:00
|
|
|
}
|
2022-01-12 06:39:18 +08:00
|
|
|
|
|
|
|
|
func TestSetupWorkarounds(t *testing.T) {
|
|
|
|
|
var o OpcUA
|
|
|
|
|
o.codes = []ua.StatusCode{ua.StatusOK}
|
|
|
|
|
|
|
|
|
|
o.Workarounds.AdditionalValidStatusCodes = []string{"0xC0", "0x00AA0000"}
|
|
|
|
|
|
|
|
|
|
err := o.setupWorkarounds()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
require.Len(t, o.codes, 3)
|
|
|
|
|
require.Equal(t, o.codes[0], ua.StatusCode(0))
|
|
|
|
|
require.Equal(t, o.codes[1], ua.StatusCode(192))
|
|
|
|
|
require.Equal(t, o.codes[2], ua.StatusCode(11141120))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCheckStatusCode(t *testing.T) {
|
|
|
|
|
var o OpcUA
|
|
|
|
|
o.codes = []ua.StatusCode{ua.StatusCode(0), ua.StatusCode(192), ua.StatusCode(11141120)}
|
|
|
|
|
require.Equal(t, o.checkStatusCode(ua.StatusCode(192)), true)
|
|
|
|
|
}
|