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

Add integration test for ListIdentity #31

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestEncodeString(t *testing.T) {
return
}

want := "ASCIISTRING82,DINT,SINT[82]"
want := "STRING,DINT,SINT[82]"
if encoding != want {
t.Errorf("encoding mismatch. Got %v want %v", encoding, want)
}
Expand Down
57 changes: 57 additions & 0 deletions tests/list_identity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package gologix_tests

import (
"testing"

"github.com/danomagnum/gologix"
)

func TestListIdentity(t *testing.T) {
// This test is a placeholder for the actual implementation
tcs := getTestConfig()
for _, tc := range tcs.ListIdentify {
t.Run(tc.Address, func(t *testing.T) {
client := gologix.NewClient(tc.Address)
err := client.Connect()
if err != nil {
t.Error(err)
return
}
defer func() {
err := client.Disconnect()
if err != nil {
t.Errorf("problem disconnecting. %v", err)
}
}()

identity, err := client.ListIdentity()
if err != nil {
t.Error(err)
return
}

if identity == nil {
t.Error("identity is nil")
return
}

if identity.ProductName != tc.ProductName {
t.Errorf("ProductName mismatch. Have %s. Want %s.", identity.ProductName, tc.ProductName)
}

version16 := uint16(tc.SoftwareVersionMinor)<<8 | uint16(tc.SoftwareVersionMajor)
if identity.Revision != version16 {
t.Errorf("Revision mismatch. Have %d. Want %d.", identity.Revision, version16)
}

if identity.SerialNumber != tc.SerialNumber {
t.Errorf("SerialNumber mismatch. Have %d. Want %d.", identity.SerialNumber, tc.SerialNumber)
}

if identity.ProductCode != tc.ProductCode {
t.Errorf("ProductCode mismatch. Have %d. Want %d.", identity.ProductCode, tc.ProductCode)
}

})
}
}
13 changes: 12 additions & 1 deletion tests/test_config template.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"SerialNumber": 1615551361,
"ProductName": "1769-L35E/B LOGIX5335E"
}
],
"README_2": "The ListIdentify is used to identify the devices on the network.",
"Readme_3": "The program will cycle through them and test each one against the list identity tests.",
"ListIdentify": [
{
"Device_Address": "192.168.2.241",
"ProductCode": 65,
"SoftwareVersionMajor": 20,
"SoftwareVersionMinor": 19,
"SerialNumber": 1615551361,
"ProductName": "1769-L35E/B LOGIX5335E"
}
]

}
12 changes: 12 additions & 0 deletions tests/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ type TestConfig struct {
SerialNumber uint32 `json:"SerialNumber"`
ProductName string `json:"ProductName"`
} `json:"PLC_List"`
ListIdentify []struct {
Address string `json:"Device_Address"`
Vendor uint16 `json:"Vendor"`
DeviceType uint16 `json:"DeviceType"`
ProductCode uint16 `json:"ProductCode"`
SoftwareVersionMajor uint16 `json:"SoftwareVersionMajor"`
SoftwareVersionMinor uint16 `json:"SoftwareVersionMinor"`
Status uint16 `json:"Status"`
SerialNumber uint32 `json:"SerialNumber"`
ProductName string `json:"ProductName"`
State uint8 `json:"State"`
} `json:"ListIdentify"`
}

func getTestConfig() TestConfig {
Expand Down