Fix test
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Previously the same byte was read for both the error code and the first byte of the checksum, which was definitely incorrect. The response is updated with an extra byte which (hopefully) provides a more accurate test case.
This commit is contained in:
parent
b3b6f28401
commit
65d89406dc
|
@ -12,7 +12,7 @@ func TestModbusValidateResponse(t *testing.T) {
|
||||||
validResponseWithExtraBytes := []byte{170, 85, 247, 3, 250, 22, 7, 15, 17, 46, 24, 11, 243, 0, 83, 0, 0, 9, 243, 9, 53, 0, 41, 0, 0, 3, 198, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 2, 9, 114, 0, 144, 19, 136, 0, 0, 13, 182, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 0, 1, 0, 0, 13, 182, 0, 0, 11, 153, 127, 255, 255, 255, 255, 255, 255, 255, 9, 112, 0, 5, 19, 136, 0, 1, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 29, 128, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 29, 0, 2, 2, 169, 127, 255, 2, 20, 1, 0, 14, 181, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 1, 255, 255, 0, 0, 0, 0, 0, 0, 34, 145, 0, 0, 1, 100, 0, 0, 34, 139, 0, 0, 1, 52, 1, 96, 0, 0, 0, 0, 0, 0, 0, 0, 13, 73, 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 2, 8, 64, 71, 0, 3, 0, 0, 255, 255, 147, 214, 1, 2, 3}
|
validResponseWithExtraBytes := []byte{170, 85, 247, 3, 250, 22, 7, 15, 17, 46, 24, 11, 243, 0, 83, 0, 0, 9, 243, 9, 53, 0, 41, 0, 0, 3, 198, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 2, 9, 114, 0, 144, 19, 136, 0, 0, 13, 182, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 0, 1, 0, 0, 13, 182, 0, 0, 11, 153, 127, 255, 255, 255, 255, 255, 255, 255, 9, 112, 0, 5, 19, 136, 0, 1, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 29, 128, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 29, 0, 2, 2, 169, 127, 255, 2, 20, 1, 0, 14, 181, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 1, 255, 255, 0, 0, 0, 0, 0, 0, 34, 145, 0, 0, 1, 100, 0, 0, 34, 139, 0, 0, 1, 52, 1, 96, 0, 0, 0, 0, 0, 0, 0, 0, 13, 73, 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 2, 8, 64, 71, 0, 3, 0, 0, 255, 255, 147, 214, 1, 2, 3}
|
||||||
invalidReadLengthResponse := []byte{170, 85, 247, 3, 250, 22, 7, 15, 17, 46, 24, 243, 0, 83, 0, 0, 9, 243, 9, 53, 0, 41, 0, 0, 3, 198, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 2, 9, 114, 0, 144, 19, 136, 0, 0, 13, 182, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 0, 1, 0, 0, 13, 182, 0, 0, 11, 153, 127, 255, 255, 255, 255, 255, 255, 255, 9, 112, 0, 5, 19, 136, 0, 1, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 29, 128, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 29, 0, 2, 2, 169, 127, 255, 2, 20, 1, 0, 14, 181, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 1, 255, 255, 0, 0, 0, 0, 0, 0, 34, 145, 0, 0, 1, 100, 0, 0, 34, 139, 0, 0, 1, 52, 1, 96, 0, 0, 0, 0, 0, 0, 0, 0, 13, 73, 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 2, 8, 64, 71, 0, 3, 0, 0, 255, 255, 147, 213}
|
invalidReadLengthResponse := []byte{170, 85, 247, 3, 250, 22, 7, 15, 17, 46, 24, 243, 0, 83, 0, 0, 9, 243, 9, 53, 0, 41, 0, 0, 3, 198, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 2, 9, 114, 0, 144, 19, 136, 0, 0, 13, 182, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 0, 1, 0, 0, 13, 182, 0, 0, 11, 153, 127, 255, 255, 255, 255, 255, 255, 255, 9, 112, 0, 5, 19, 136, 0, 1, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 29, 128, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 29, 0, 2, 2, 169, 127, 255, 2, 20, 1, 0, 14, 181, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 1, 255, 255, 0, 0, 0, 0, 0, 0, 34, 145, 0, 0, 1, 100, 0, 0, 34, 139, 0, 0, 1, 52, 1, 96, 0, 0, 0, 0, 0, 0, 0, 0, 13, 73, 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 2, 8, 64, 71, 0, 3, 0, 0, 255, 255, 147, 213}
|
||||||
invalidChecksumResponse := []byte{170, 85, 247, 3, 250, 22, 7, 15, 17, 46, 24, 11, 243, 0, 83, 0, 0, 9, 243, 9, 53, 0, 41, 0, 0, 3, 198, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 2, 9, 114, 0, 144, 19, 136, 0, 0, 13, 182, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 0, 1, 0, 0, 13, 182, 0, 0, 11, 153, 127, 255, 255, 255, 255, 255, 255, 255, 9, 112, 0, 5, 19, 136, 0, 1, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 29, 128, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 29, 0, 2, 2, 169, 127, 255, 2, 20, 1, 0, 14, 181, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 1, 255, 255, 0, 0, 0, 0, 0, 0, 34, 145, 0, 0, 1, 100, 0, 0, 34, 139, 0, 0, 1, 52, 1, 96, 0, 0, 0, 0, 0, 0, 0, 0, 13, 73, 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 2, 8, 64, 71, 0, 3, 0, 0, 255, 255, 147, 213}
|
invalidChecksumResponse := []byte{170, 85, 247, 3, 250, 22, 7, 15, 17, 46, 24, 11, 243, 0, 83, 0, 0, 9, 243, 9, 53, 0, 41, 0, 0, 3, 198, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 2, 9, 114, 0, 144, 19, 136, 0, 0, 13, 182, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 0, 1, 0, 0, 13, 182, 0, 0, 11, 153, 127, 255, 255, 255, 255, 255, 255, 255, 9, 112, 0, 5, 19, 136, 0, 1, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 29, 128, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 29, 0, 2, 2, 169, 127, 255, 2, 20, 1, 0, 14, 181, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 1, 255, 255, 0, 0, 0, 0, 0, 0, 34, 145, 0, 0, 1, 100, 0, 0, 34, 139, 0, 0, 1, 52, 1, 96, 0, 0, 0, 0, 0, 0, 0, 0, 13, 73, 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 2, 8, 64, 71, 0, 3, 0, 0, 255, 255, 147, 213}
|
||||||
failureCodeResponse := []byte{170, 85, 0, 0, 1, 176}
|
failureCodeResponse := []byte{170, 85, 0, 0, 2, 240, 1}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -36,7 +36,7 @@ func TestModbusValidateResponse(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "failure code rcvd",
|
name: "failure code rcvd",
|
||||||
resp: failureCodeResponse,
|
resp: failureCodeResponse,
|
||||||
wantErr: "command failed with code: 1, error: FailureCodeIllegalFunction",
|
wantErr: "command failed with code: 2, error: FailureCodeIllegalDataAddress",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid response with extra bytes",
|
name: "valid response with extra bytes",
|
||||||
|
|
Loading…
Reference in New Issue