Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-2276: fix for same Item.Start but different Item.Bit access #108

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion s7comm_plugin/s7comm.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import (
"context"
"errors"
"fmt"
"reflect"
"regexp"
"strconv"
"time"
@@ -179,7 +180,7 @@ func ParseAddresses(addresses []string, batchMaxSize int) ([][]S7DataItemWithAdd
if i == j {
continue
}
if a.Item.Area == b.Item.Area && a.Item.DBNumber == b.Item.DBNumber && a.Item.Start == b.Item.Start {
if reflect.DeepEqual(a.Item, b.Item) {
return nil, fmt.Errorf("duplicate address %v", a)
}
}
51 changes: 51 additions & 0 deletions s7comm_plugin/s7comm_test.go
Original file line number Diff line number Diff line change
@@ -59,6 +59,57 @@ var _ = Describe("S7Comm Plugin Unittests", func() {
}
})
})

type S7Addresses struct {
addresses []string
expectedErrMsg []string
}

DescribeTable("Parsing duplicate Addresses", func(entries S7Addresses) {
batchMaxSize := 1

_, err := s7comm_plugin.ParseAddresses(entries.addresses, batchMaxSize)

if entries.expectedErrMsg != nil {
Expect(err).To(HaveOccurred())
for _, containedErrStr := range entries.expectedErrMsg {
Expect(err.Error()).To(ContainSubstring(containedErrStr))
}
return
}
Expect(err).NotTo(HaveOccurred())
},
Entry("same DBNumber but different Item.Start",
S7Addresses{
addresses: []string{"DB2.W0", "DB2.W2"},
expectedErrMsg: nil,
}),
Entry("same DBNumber but different Item.Bit",
S7Addresses{
addresses: []string{"DB2.X0.0", "DB2.X0.1"},
expectedErrMsg: nil,
}),
Entry("same Bit but different Item.DBNumber",
S7Addresses{
addresses: []string{"DB2.X0.0", "DB3.X0.0"},
expectedErrMsg: nil,
}),
Entry("same Area but different Item.Bit",
S7Addresses{
addresses: []string{"PE2.X0.0", "PE2.X0.1"},
expectedErrMsg: nil,
}),
Entry("same DBNumber and same Item.Area",
S7Addresses{
addresses: []string{"DB2.W0", "DB2.W2", "DB2.W0"},
expectedErrMsg: []string{"duplicate address", "DB2.W0"},
}),
Entry("same DBNumber and same Item.Bit",
S7Addresses{
addresses: []string{"DB2.X0.0", "DB2.W2", "DB2.X0.0"},
expectedErrMsg: []string{"duplicate address", "DB2.X0.0"},
}),
)
})

var _ = Describe("S7Comm Test Against Local PLC", func() {

Unchanged files with check annotations Beta

// Check if environment variables are set
if testModbusSimulator == "" {
Skip("Skipping test: environment variables not set")

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:14.942

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:14.942

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-nodered-js

BeforeEach 01/21/25 12:46:30.177

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-nodered-js

BeforeEach 01/21/25 12:46:30.177

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:31.259

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:31.16

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:36.442

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:36.442

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:48.868

Check notice on line 23 in modbus_plugin/modbus_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:48.869
return
}
// Check if environment variables are set
if testActivated == "" {
Skip("Skipping Node-RED JS tests: TEST_NODERED_JS not set")

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:28.364

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:28.364

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:28.364

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:28.364

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:28.364

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:28.364

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:28.364

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-sensorconnect

BeforeEach 01/21/25 12:46:28.365

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:46.36

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:46.455

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:46.457

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:46.558

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:46.556

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:46.556

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:46.556

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-tag-processor

BeforeEach 01/21/25 12:46:46.559

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:48.436

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:48.437

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:48.44

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:48.545

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:48.636

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:48.636

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:48.637

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-s7-plc

BeforeEach 01/21/25 12:46:48.548

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:50.117

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:50.117

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:50.12

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:50.121

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:50.121

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:50.121

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:50.121

Check notice on line 24 in nodered_js_plugin/nodered_js_plugin_test.go

GitHub Actions / go-test-opcua-plc

BeforeEach 01/21/25 13:00:50.121
return
}
})
// Check if environment variables are set
if endpoint == "" {
Skip("Skipping test: environment variables not set")

Check notice on line 117 in opcua_plugin/opcua_other_simulators_test.go

GitHub Actions / go-test-nodered-js

BeforeEach 01/21/25 12:46:47.273
return
}
// Check if environment variables are set
if endpoint == "" {
Skip("Skipping test: environment variables not set")

Check notice on line 189 in opcua_plugin/opcua_other_simulators_test.go

GitHub Actions / go-test-nodered-js

BeforeEach 01/21/25 12:46:47.08

Check notice on line 189 in opcua_plugin/opcua_other_simulators_test.go

GitHub Actions / go-test-nodered-js

BeforeEach 01/21/25 12:46:47.272

Check notice on line 189 in opcua_plugin/opcua_other_simulators_test.go

GitHub Actions / go-test-nodered-js

BeforeEach 01/21/25 12:46:47.274

Check notice on line 189 in opcua_plugin/opcua_other_simulators_test.go

GitHub Actions / go-test-nodered-js

BeforeEach 01/21/25 12:46:47.38
return
}
Context("When browsing a folder structure with HasTypeDefinition and HasChild references", func() {
It("should browse through ABC folder and return the ProcessValue variable", func() {
Skip("fake opc ua node browser cannot handle this, as children wiull always return all referencednodes independent of the nodeclass")

Check notice on line 323 in opcua_plugin/opcua_unittest_test.go

GitHub Actions / go-test-nodered-js

It 01/21/25 12:46:47.072
// Create ABC folder node
abcFolder := createMockVariableNode(1234, "ABC")
abcFolder.attributes = append(abcFolder.attributes, getDataValueForNodeClass(ua.NodeClassObject))
Context("When GetNodeTree is called for a PLC", func() {
It("should return a node tree", func() {
if endpoint == "" {
Skip("Skipping test: environment variables not set")

Check notice on line 41 in opcua_plugin/opcua_plc_test.go

GitHub Actions / go-test-nodered-js

It 01/21/25 12:46:47.48
return
}
opc := &OPCUAInput{
// Check if environment variables are set
if endpoint == "" || username == "" || password == "" {
Skip("Skipping test: environment variables not set")

Check notice on line 203 in opcua_plugin/opcua_plc_test.go

GitHub Actions / go-test-nodered-js

BeforeEach 01/21/25 12:46:47.722
return
}