You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/05/02 16:51:48 UTC
[plc4x] branch develop updated (fe482d9305 -> 7cc564ff82)
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
from fe482d9305 refactor(plc4go/spi): introduce RequestTransactionRunnable
new b691072288 test(plc4go/spi): add test for ResponseItem
new ab8bfd8a17 feat(plc4go/spi): implement GetConnectionUrl for options
new 7cc564ff82 refactor(plc4go): avoid panics if possible
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
plc4go/internal/ads/Discoverer.go | 5 +-
plc4go/internal/ads/model/Tag.go | 2 +-
plc4go/internal/cbus/CBusMessageMapper.go | 45 +++++---
plc4go/internal/cbus/TagHandler.go | 16 +--
plc4go/internal/cbus/ValueHandler.go | 132 ++++++++++++------------
plc4go/internal/eip/Reader.go | 4 +-
plc4go/internal/simulated/Connection.go | 4 +-
plc4go/pkg/api/cache/plcConnectionLease_test.go | 4 +-
plc4go/pkg/api/driverManager.go | 6 --
plc4go/spi/default/DefaultConnection.go | 10 +-
plc4go/spi/default/DefaultConnection_test.go | 10 +-
plc4go/spi/model/DefaultPlcDiscoveryItem.go | 15 ++-
plc4go/spi/model/render_test.go | 1 +
plc4go/spi/testutils/DriverTestRunner.go | 2 +-
plc4go/spi/testutils/ManualTestRunner.go | 6 +-
plc4go/spi/utils/ReadBufferByteBased.go | 2 +-
plc4go/spi/utils/WriteBufferBoxBased.go | 3 +-
plc4go/spi/utils/WriteBufferJsonBased.go | 42 ++++----
plc4go/spi/values/WriteBufferPlcValueBased.go | 36 +++----
19 files changed, 178 insertions(+), 167 deletions(-)
[plc4x] 03/03: refactor(plc4go): avoid panics if possible
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 7cc564ff827c1bd1fcf0a0dc6788363290229000
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue May 2 18:51:40 2023 +0200
refactor(plc4go): avoid panics if possible
---
plc4go/internal/ads/Discoverer.go | 5 +-
plc4go/internal/ads/model/Tag.go | 2 +-
plc4go/internal/cbus/CBusMessageMapper.go | 45 +++++---
plc4go/internal/cbus/TagHandler.go | 16 +--
plc4go/internal/cbus/ValueHandler.go | 132 ++++++++++++------------
plc4go/internal/eip/Reader.go | 4 +-
plc4go/internal/simulated/Connection.go | 4 +-
plc4go/pkg/api/cache/plcConnectionLease_test.go | 4 +-
plc4go/pkg/api/driverManager.go | 6 --
plc4go/spi/default/DefaultConnection.go | 10 +-
plc4go/spi/default/DefaultConnection_test.go | 10 +-
plc4go/spi/testutils/DriverTestRunner.go | 2 +-
plc4go/spi/testutils/ManualTestRunner.go | 6 +-
plc4go/spi/utils/ReadBufferByteBased.go | 2 +-
plc4go/spi/utils/WriteBufferBoxBased.go | 3 +-
plc4go/spi/utils/WriteBufferJsonBased.go | 42 ++++----
plc4go/spi/values/WriteBufferPlcValueBased.go | 36 +++----
17 files changed, 165 insertions(+), 164 deletions(-)
diff --git a/plc4go/internal/ads/Discoverer.go b/plc4go/internal/ads/Discoverer.go
index f1d4fa25aa..c9ce8efeb8 100644
--- a/plc4go/internal/ads/Discoverer.go
+++ b/plc4go/internal/ads/Discoverer.go
@@ -23,6 +23,7 @@ import (
"context"
"encoding/binary"
"fmt"
+ "github.com/pkg/errors"
"net"
"net/url"
"strconv"
@@ -131,11 +132,11 @@ func (d *Discoverer) Discover(ctx context.Context, callback func(event apiModel.
for _, discoveryItem := range discoveryItems {
responseAddr, err := net.ResolveUDPAddr("udp4", fmt.Sprintf("%s:%d", discoveryItem.localAddress, model.AdsDiscoveryConstants_ADSDISCOVERYUDPDEFAULTPORT))
if err != nil {
- panic(err)
+ return errors.Wrap(err, "error resolving udp")
}
socket, err := net.ListenUDP("udp4", responseAddr)
if err != nil {
- panic(err)
+ return errors.Wrap(err, "error listening udp")
}
discoveryItem.socket = socket
diff --git a/plc4go/internal/ads/model/Tag.go b/plc4go/internal/ads/model/Tag.go
index 6f77f701c0..868466799e 100644
--- a/plc4go/internal/ads/model/Tag.go
+++ b/plc4go/internal/ads/model/Tag.go
@@ -158,7 +158,7 @@ func (m DirectPlcTag) SerializeWithWriteBuffer(writeBuffer utils.WriteBuffer) er
}
func (m DirectPlcTag) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
- panic(name)
+ return xml.Attr{}, errors.Errorf("%s", name) // TODO: why did this panic before
}
type SymbolicPlcTag struct {
diff --git a/plc4go/internal/cbus/CBusMessageMapper.go b/plc4go/internal/cbus/CBusMessageMapper.go
index a8e5ca53a1..a51e604dbf 100644
--- a/plc4go/internal/cbus/CBusMessageMapper.go
+++ b/plc4go/internal/cbus/CBusMessageMapper.go
@@ -96,7 +96,8 @@ func TagToCBusMessage(tag apiModel.PlcTag, value apiValues.PlcValue, alphaGenera
var salData readWriteModel.SALData
switch tagType.application.ApplicationId() {
case readWriteModel.ApplicationId_FREE_USAGE:
- panic("Not yet implemented") // TODO: implement
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_TEMPERATURE_BROADCAST:
var temperatureBroadcastData readWriteModel.TemperatureBroadcastData
switch salCommand {
@@ -114,7 +115,8 @@ func TagToCBusMessage(tag apiModel.PlcTag, value apiValues.PlcValue, alphaGenera
}
salData = readWriteModel.NewSALDataTemperatureBroadcast(temperatureBroadcastData, nil)
case readWriteModel.ApplicationId_ROOM_CONTROL_SYSTEM:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case
readWriteModel.ApplicationId_LIGHTING,
readWriteModel.ApplicationId_VENTILATION,
@@ -166,35 +168,48 @@ func TagToCBusMessage(tag apiModel.PlcTag, value apiValues.PlcValue, alphaGenera
lightingData = readWriteModel.NewLightingDataTerminateRamp(group, commandTypeContainer)
supportsWrite = true
case readWriteModel.LightingCommandType_LABEL.PLC4XEnumName():
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
default:
return nil, false, false, false, errors.Errorf("Unsupported command %s for %s", salCommand, tagType.application.ApplicationId())
}
salData = readWriteModel.NewSALDataLighting(lightingData, nil)
case readWriteModel.ApplicationId_AIR_CONDITIONING:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_TRIGGER_CONTROL:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_ENABLE_CONTROL:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_SECURITY:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_METERING:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_ACCESS_CONTROL:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_CLOCK_AND_TIMEKEEPING:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_TELEPHONY_STATUS_AND_CONTROL:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_MEASUREMENT:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_TESTING:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_MEDIA_TRANSPORT_CONTROL:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
case readWriteModel.ApplicationId_ERROR_REPORTING:
- panic("Implement me")
+ err = errors.New("Not yet implemented") // TODO: implement
+ return
default:
return nil, false, false, false, errors.Errorf("No support for %s", tagType.application)
}
diff --git a/plc4go/internal/cbus/TagHandler.go b/plc4go/internal/cbus/TagHandler.go
index 5da0695fbf..4fb943ef1d 100644
--- a/plc4go/internal/cbus/TagHandler.go
+++ b/plc4go/internal/cbus/TagHandler.go
@@ -145,8 +145,8 @@ func (m TagHandler) handleStatusRequestPattern(match map[string]string) (apiMode
} else if levelArgument := match["startingGroupAddressLabel"]; levelArgument != "" {
statusRequestType = StatusRequestTypeLevel
decodedHex, _ := hex.DecodeString(levelArgument)
- if len(decodedHex) != 1 {
- panic("invalid state. Should have exactly 1")
+ if hexLength := len(decodedHex); hexLength != 1 {
+ return nil, errors.Errorf("invalid state. Should have exactly 1. Actual length %d", hexLength)
}
startingGroupAddressLabel = &decodedHex[0]
} else {
@@ -177,7 +177,7 @@ func (m TagHandler) handleCalPattern(match map[string]string) (apiModel.PlcTag,
calTypeArgument := match["calType"]
switch {
case strings.HasPrefix(calTypeArgument, "reset"):
- panic("Not implemented") // TODO: implement me
+ return nil, errors.New("Not implemented") // TODO: implement me
case strings.HasPrefix(calTypeArgument, "recall="):
var recalParamNo readWriteModel.Parameter
recallParamNoArgument := match["recallParamNo"]
@@ -263,15 +263,15 @@ func (m TagHandler) handleCalPattern(match map[string]string) (apiModel.PlcTag,
count = uint8(atoi)
return NewCALGetStatusTag(unitAddress, bridgeAddresses, recalParamNo, count, 1), nil
case strings.HasPrefix(calTypeArgument, "write="):
- panic("Not implemented") // TODO: implement me
+ return nil, errors.New("Not implemented") // TODO: implement me
case strings.HasPrefix(calTypeArgument, "identifyReply="):
- panic("Not implemented") // TODO: implement me
+ return nil, errors.New("Not implemented") // TODO: implement me
case strings.HasPrefix(calTypeArgument, "reply="):
- panic("Not implemented") // TODO: implement me
+ return nil, errors.New("Not implemented") // TODO: implement me
case strings.HasPrefix(calTypeArgument, "status="):
- panic("Not implemented") // TODO: implement me
+ return nil, errors.New("Not implemented") // TODO: implement me
case strings.HasPrefix(calTypeArgument, "statusExtended="):
- panic("Not implemented") // TODO: implement me
+ return nil, errors.New("Not implemented") // TODO: implement me
default:
return nil, errors.Errorf("Invalid cal type %s", calTypeArgument)
}
diff --git a/plc4go/internal/cbus/ValueHandler.go b/plc4go/internal/cbus/ValueHandler.go
index a58dd6201f..1bdb4638b2 100644
--- a/plc4go/internal/cbus/ValueHandler.go
+++ b/plc4go/internal/cbus/ValueHandler.go
@@ -45,7 +45,7 @@ func (m ValueHandler) NewPlcValue(tag apiModel.PlcTag, value any) (apiValues.Plc
CAL_IDENTIFY_REPLY,
CAL_STATUS,
CAL_STATUS_EXTENDED:
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case SAL:
var curValues []any
if len(tag.GetArrayInfo()) > 0 && tag.GetArrayInfo()[0].GetSize() > 1 {
@@ -143,7 +143,7 @@ func (m ValueHandler) NewPlcValue(tag apiModel.PlcTag, value any) (apiValues.Plc
}
return group, nil
case readWriteModel.LightingCommandType_LABEL.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
@@ -156,13 +156,13 @@ func (m ValueHandler) NewPlcValue(tag apiModel.PlcTag, value any) (apiValues.Plc
}
return zoneGroup, nil
case readWriteModel.AirConditioningCommandType_ZONE_HVAC_PLANT_STATUS.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_ZONE_HUMIDITY_PLANT_STATUS.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_ZONE_TEMPERATURE.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_ZONE_HUMIDITY.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_REFRESH.PLC4XEnumName():
zoneGroup, err := m.DefaultValueHandler.NewPlcValueFromType(apiValues.BYTE, curValues[0])
if err != nil {
@@ -170,23 +170,23 @@ func (m ValueHandler) NewPlcValue(tag apiModel.PlcTag, value any) (apiValues.Plc
}
return zoneGroup, nil
case readWriteModel.AirConditioningCommandType_SET_ZONE_HVAC_MODE.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_PLANT_HVAC_LEVEL.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_ZONE_HUMIDITY_MODE.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_PLANT_HUMIDITY_LEVEL.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_HVAC_UPPER_GUARD_LIMIT.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_HVAC_LOWER_GUARD_LIMIT.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_HVAC_SETBACK_LIMIT.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_HUMIDITY_UPPER_GUARD_LIMIT.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_HUMIDITY_LOWER_GUARD_LIMIT.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_SET_ZONE_GROUP_ON.PLC4XEnumName():
zoneGroup, err := m.DefaultValueHandler.NewPlcValueFromType(apiValues.BYTE, curValues[0])
if err != nil {
@@ -194,95 +194,95 @@ func (m ValueHandler) NewPlcValue(tag apiModel.PlcTag, value any) (apiValues.Plc
}
return zoneGroup, nil
case readWriteModel.AirConditioningCommandType_SET_HUMIDITY_SETBACK_LIMIT.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_HVAC_SCHEDULE_ENTRY.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AirConditioningCommandType_HUMIDITY_SCHEDULE_ENTRY.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_TRIGGER_CONTROL:
switch salCommand {
case readWriteModel.TriggerControlCommandType_TRIGGER_EVENT.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.TriggerControlCommandType_TRIGGER_MIN.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.TriggerControlCommandType_TRIGGER_MAX.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.TriggerControlCommandType_INDICATOR_KILL.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.TriggerControlCommandType_LABEL.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_ENABLE_CONTROL:
switch salCommand {
case readWriteModel.EnableControlCommandType_SET_NETWORK_VARIABLE.PLC4XEnumName():
- panic("Implement me") //TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_SECURITY:
switch salCommand {
case readWriteModel.SecurityCommandType_OFF.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.SecurityCommandType_ON.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.SecurityCommandType_EVENT.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_METERING:
switch salCommand {
case readWriteModel.MeteringCommandType_EVENT.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_ACCESS_CONTROL:
switch salCommand {
case readWriteModel.AccessControlCommandType_CLOSE_ACCESS_POINT.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AccessControlCommandType_LOCK_ACCESS_POINT.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AccessControlCommandType_ACCESS_POINT_LEFT_OPEN.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AccessControlCommandType_ACCESS_POINT_FORCED_OPEN.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AccessControlCommandType_ACCESS_POINT_CLOSED.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AccessControlCommandType_REQUEST_TO_EXIT.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AccessControlCommandType_VALID_ACCESS.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.AccessControlCommandType_INVALID_ACCESS.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_CLOCK_AND_TIMEKEEPING:
switch salCommand {
case readWriteModel.ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
case readWriteModel.ClockAndTimekeepingCommandType_REQUEST_REFRESH.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_TELEPHONY_STATUS_AND_CONTROL:
switch salCommand {
case readWriteModel.TelephonyCommandType_EVENT.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_MEASUREMENT:
switch salCommand {
case readWriteModel.MeasurementCommandType_MEASUREMENT_EVENT.PLC4XEnumName():
- panic("Implement me") // TODO: implement
+ return nil, errors.New("Implement me") //TODO: implement me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
@@ -295,62 +295,62 @@ func (m ValueHandler) NewPlcValue(tag apiModel.PlcTag, value any) (apiValues.Plc
case readWriteModel.ApplicationId_MEDIA_TRANSPORT_CONTROL:
switch salCommand {
case readWriteModel.MediaTransportControlCommandType_STOP.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_PLAY.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_PAUSE_RESUME.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_SELECT_CATEGORY.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_SELECT_SELECTION.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_SELECT_TRACK.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_SHUFFLE_ON_OFF.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_REPEAT_ON_OFF.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_NEXT_PREVIOUS_CATEGORY.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_NEXT_PREVIOUS_SELECTION.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_NEXT_PREVIOUS_TRACK.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_FAST_FORWARD.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_REWIND.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_SOURCE_POWER_CONTROL.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_TOTAL_TRACKS.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_STATUS_REQUEST.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_ENUMERATE_CATEGORIES_SELECTIONS_TRACKS.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_ENUMERATION_SIZE.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_TRACK_NAME.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_SELECTION_NAME.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_CATEGORY_NAME.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.MediaTransportControlCommandType_FAST_FORWARD.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
case readWriteModel.ApplicationId_ERROR_REPORTING:
switch salCommand {
case readWriteModel.ErrorReportingCommandType_DEPRECATED.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.ErrorReportingCommandType_ERROR_REPORT.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.ErrorReportingCommandType_ACKNOWLEDGE.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
case readWriteModel.ErrorReportingCommandType_CLEAR_MOST_SEVERE.PLC4XEnumName():
- panic("Implement me") // TODO: implement me
+ return nil, errors.New("Implement me") //TODO: implement me me
default:
return nil, errors.Errorf("Unsupported command %s for %s", salCommand, tmpSalTag.application.ApplicationId())
}
diff --git a/plc4go/internal/eip/Reader.go b/plc4go/internal/eip/Reader.go
index 6526071542..3348aecde0 100644
--- a/plc4go/internal/eip/Reader.go
+++ b/plc4go/internal/eip/Reader.go
@@ -281,7 +281,7 @@ func parsePlcValue(tag EIPPlcTag, data utils.ReadBufferByteBased, _type readWrit
list = append(list, spiValues.NewPlcSINT(readInt8))
case readWriteModel.CIPDataTypeCode_REAL:
if _type.Size()*8 != 64 {
- panic("Unexpected size")
+ return nil, errors.New("Unexpected size")
}
readFloat64, err := data.ReadFloat64("", 64)
if err != nil {
@@ -321,7 +321,7 @@ func parsePlcValue(tag EIPPlcTag, data utils.ReadBufferByteBased, _type readWrit
return spiValues.NewPlcDINT(readInt32), nil
case readWriteModel.CIPDataTypeCode_REAL:
if _type.Size()*8 != 64 {
- panic("Unexpected size")
+ return nil, errors.New("Unexpected size")
}
readFloat32, err := data.ReadFloat32("", 64)
if err != nil {
diff --git a/plc4go/internal/simulated/Connection.go b/plc4go/internal/simulated/Connection.go
index e6ef48d492..a56287d140 100644
--- a/plc4go/internal/simulated/Connection.go
+++ b/plc4go/internal/simulated/Connection.go
@@ -241,9 +241,9 @@ func (c *Connection) SubscriptionRequestBuilder() model.PlcSubscriptionRequestBu
}
func (c *Connection) UnsubscriptionRequestBuilder() model.PlcUnsubscriptionRequestBuilder {
- panic("not implemented")
+ panic("not provided by simulated connection")
}
func (c *Connection) BrowseRequestBuilder() model.PlcBrowseRequestBuilder {
- panic("not implemented")
+ panic("not provided by simulated connection")
}
diff --git a/plc4go/pkg/api/cache/plcConnectionLease_test.go b/plc4go/pkg/api/cache/plcConnectionLease_test.go
index a90141d224..5ed63ab180 100644
--- a/plc4go/pkg/api/cache/plcConnectionLease_test.go
+++ b/plc4go/pkg/api/cache/plcConnectionLease_test.go
@@ -565,7 +565,7 @@ func TestLeasedPlcConnection_UnsubscriptionRequestBuilder(t *testing.T) {
func() {
defer func() {
if r := recover(); r != nil {
- assert.Equal(t, r, "not implemented")
+ assert.Equal(t, r, "not provided by simulated connection")
} else {
t.Errorf("The code did not panic")
}
@@ -615,7 +615,7 @@ func TestLeasedPlcConnection_BrowseRequestBuilder(t *testing.T) {
func() {
defer func() {
if r := recover(); r != nil {
- assert.Equal(t, r, "not implemented")
+ assert.Equal(t, r, "not provided by simulated connection")
} else {
t.Errorf("The code did not panic")
}
diff --git a/plc4go/pkg/api/driverManager.go b/plc4go/pkg/api/driverManager.go
index 2e182dda8d..411f4979e9 100644
--- a/plc4go/pkg/api/driverManager.go
+++ b/plc4go/pkg/api/driverManager.go
@@ -137,9 +137,6 @@ func convertToInternalOptions(withDiscoveryOptions ...WithDiscoveryOption) []opt
///////////////////////////////////////
func (m *plcDriverManger) RegisterDriver(driver PlcDriver) {
- if driver == nil {
- panic("driver must not be nil")
- }
log.Debug().Str("protocolName", driver.GetProtocolName()).Msg("Registering driver")
// If this driver is already registered, just skip resetting it
for driverName := range m.drivers {
@@ -170,9 +167,6 @@ func (m *plcDriverManger) GetDriver(driverName string) (PlcDriver, error) {
}
func (m *plcDriverManger) RegisterTransport(transport transports.Transport) {
- if transport == nil {
- panic("transport must not be nil")
- }
log.Debug().Str("transportName", transport.GetTransportName()).Msg("Registering transport")
// If this transport is already registered, just skip resetting it
for transportName := range m.transports {
diff --git a/plc4go/spi/default/DefaultConnection.go b/plc4go/spi/default/DefaultConnection.go
index 798548bf8a..7ce2a07cdf 100644
--- a/plc4go/spi/default/DefaultConnection.go
+++ b/plc4go/spi/default/DefaultConnection.go
@@ -307,23 +307,23 @@ func (d *defaultConnection) GetMetadata() model.PlcConnectionMetadata {
}
func (d *defaultConnection) ReadRequestBuilder() model.PlcReadRequestBuilder {
- panic("not implemented")
+ panic("not provided by actual connection")
}
func (d *defaultConnection) WriteRequestBuilder() model.PlcWriteRequestBuilder {
- panic("not implemented")
+ panic("not provided by actual connection")
}
func (d *defaultConnection) SubscriptionRequestBuilder() model.PlcSubscriptionRequestBuilder {
- panic("not implemented")
+ panic("not provided by actual connection")
}
func (d *defaultConnection) UnsubscriptionRequestBuilder() model.PlcUnsubscriptionRequestBuilder {
- panic("not implemented")
+ panic("not provided by actual connection")
}
func (d *defaultConnection) BrowseRequestBuilder() model.PlcBrowseRequestBuilder {
- panic("not implemented")
+ panic("not provided by actual connection")
}
func (d *defaultConnection) GetTransportInstance() transports.TransportInstance {
diff --git a/plc4go/spi/default/DefaultConnection_test.go b/plc4go/spi/default/DefaultConnection_test.go
index d07b02c5db..f6d46ab64b 100644
--- a/plc4go/spi/default/DefaultConnection_test.go
+++ b/plc4go/spi/default/DefaultConnection_test.go
@@ -477,7 +477,7 @@ func Test_defaultConnection_BrowseRequestBuilder(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
defer func() {
if err := recover(); err != nil {
- assert.Equal(t, "not implemented", err)
+ assert.Equal(t, "not provided by actual connection", err)
} else {
t.Error("should fail")
}
@@ -903,7 +903,7 @@ func Test_defaultConnection_ReadRequestBuilder(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
defer func() {
if err := recover(); err != nil {
- assert.Equal(t, "not implemented", err)
+ assert.Equal(t, "not provided by actual connection", err)
} else {
t.Error("should fail")
}
@@ -975,7 +975,7 @@ func Test_defaultConnection_SubscriptionRequestBuilder(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
defer func() {
if err := recover(); err != nil {
- assert.Equal(t, "not implemented", err)
+ assert.Equal(t, "not provided by actual connection", err)
} else {
t.Error("should fail")
}
@@ -1013,7 +1013,7 @@ func Test_defaultConnection_UnsubscriptionRequestBuilder(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
defer func() {
if err := recover(); err != nil {
- assert.Equal(t, "not implemented", err)
+ assert.Equal(t, "not provided by actual connection", err)
} else {
t.Error("should fail")
}
@@ -1051,7 +1051,7 @@ func Test_defaultConnection_WriteRequestBuilder(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
defer func() {
if err := recover(); err != nil {
- assert.Equal(t, "not implemented", err)
+ assert.Equal(t, "not provided by actual connection", err)
} else {
t.Error("should fail")
}
diff --git a/plc4go/spi/testutils/DriverTestRunner.go b/plc4go/spi/testutils/DriverTestRunner.go
index c3a971acc5..58c2d9feea 100644
--- a/plc4go/spi/testutils/DriverTestRunner.go
+++ b/plc4go/spi/testutils/DriverTestRunner.go
@@ -323,7 +323,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti
}
actualRawOutput := testTransportInstance.DrainWriteBuffer(expectedRawOutputLength)
if testTransportInstance.GetNumDrainableBytes() != 0 {
- //panic(fmt.Sprintf("leftover drainable bytes (%d)", testTransportInstance.GetNumDrainableBytes()))
+ t.Logf("leftover drainable bytes (%d)", testTransportInstance.GetNumDrainableBytes())
}
var bufferFactory func([]byte, ...utils.ReadBufferByteBasedOptions) utils.ReadBufferByteBased
diff --git a/plc4go/spi/testutils/ManualTestRunner.go b/plc4go/spi/testutils/ManualTestRunner.go
index 2ec36ccfde..d0d5bb0dc4 100644
--- a/plc4go/spi/testutils/ManualTestRunner.go
+++ b/plc4go/spi/testutils/ManualTestRunner.go
@@ -112,14 +112,14 @@ func (m *ManualTestSuite) runSingleTest(t *testing.T, connection plc4go.PlcConne
readRequestBuilder.AddTagAddress(tagName, testCase.Address)
readRequest, err := readRequestBuilder.Build()
if err != nil {
- panic(err)
+ t.Fatal(err)
+ return
}
// Execute the read request
readResponseResult := <-readRequest.Execute()
if readResponseResult.GetErr() != nil {
- t.Errorf("Error getting response %v", readResponseResult.GetErr())
- t.FailNow()
+ t.Fatalf("Error getting response %v", readResponseResult.GetErr())
return
}
readResponse := readResponseResult.GetResponse()
diff --git a/plc4go/spi/utils/ReadBufferByteBased.go b/plc4go/spi/utils/ReadBufferByteBased.go
index 3ffa13c66a..d9957e538f 100644
--- a/plc4go/spi/utils/ReadBufferByteBased.go
+++ b/plc4go/spi/utils/ReadBufferByteBased.go
@@ -96,7 +96,7 @@ func (rb *byteReadBuffer) Reset(pos uint16) {
bytesToSkip := make([]byte, pos)
_, err := rb.reader.Read(bytesToSkip)
if err != nil {
- panic(err)
+ panic(errors.Wrap(err, "Should not happen")) // TODO: maybe this is a possible occurence since we accept a argument, better returns a error
}
rb.pos = uint64(pos * 8)
}
diff --git a/plc4go/spi/utils/WriteBufferBoxBased.go b/plc4go/spi/utils/WriteBufferBoxBased.go
index b076cb51ff..f706a90f76 100644
--- a/plc4go/spi/utils/WriteBufferBoxBased.go
+++ b/plc4go/spi/utils/WriteBufferBoxBased.go
@@ -23,6 +23,7 @@ import (
"container/list"
"context"
"fmt"
+ "github.com/pkg/errors"
"math/big"
)
@@ -264,7 +265,7 @@ findTheBox:
finalBoxes = append(asciiBoxes, finalBoxes...)
break findTheBox
default:
- panic("We should never reach this point")
+ return errors.New("We should never reach this point")
}
}
if b.mergeSingleBoxes && len(finalBoxes) == 1 {
diff --git a/plc4go/spi/utils/WriteBufferJsonBased.go b/plc4go/spi/utils/WriteBufferJsonBased.go
index 98000381f2..c6eca9b29d 100644
--- a/plc4go/spi/utils/WriteBufferJsonBased.go
+++ b/plc4go/spi/utils/WriteBufferJsonBased.go
@@ -198,17 +198,15 @@ func (j *jsonWriteBuffer) PopContext(logicalName string, _ ...WithWriterArgs) er
pop := j.Pop()
var poppedName string
var unwrapped any
- switch pop.(type) {
+ switch _context := pop.(type) {
case *elementContext:
- context := pop.(*elementContext)
- poppedName = context.logicalName
- unwrapped = context.properties
+ poppedName = _context.logicalName
+ unwrapped = _context.properties
case *listContext:
- context := pop.(*listContext)
- poppedName = context.logicalName
- unwrapped = context.list
+ poppedName = _context.logicalName
+ unwrapped = _context.list
default:
- panic("broken context")
+ return errors.New("broken context")
}
if poppedName != logicalName {
return errors.Errorf("unexpected closing context %s, expected %s", poppedName, logicalName)
@@ -220,17 +218,15 @@ func (j *jsonWriteBuffer) PopContext(logicalName string, _ ...WithWriterArgs) er
return nil
}
j.rootNode = j.Peek()
- switch j.rootNode.(type) {
+ switch _context := j.rootNode.(type) {
case *elementContext:
- context := j.rootNode.(*elementContext)
- context.properties[logicalName] = unwrapped
+ _context.properties[logicalName] = unwrapped
case *listContext:
- context := j.rootNode.(*listContext)
wrappedWrap := make(map[string]any)
wrappedWrap[logicalName] = unwrapped
- context.list = append(context.list, wrappedWrap)
+ _context.list = append(_context.list, wrappedWrap)
default:
- panic("broken context")
+ return errors.New("broken context")
}
return nil
}
@@ -249,30 +245,28 @@ func (j *jsonWriteBuffer) GetJsonString() (string, error) {
func (j *jsonWriteBuffer) encodeNode(logicalName string, value any, attr map[string]any, _ ...WithWriterArgs) error {
logicalName = j.SanitizeLogicalName(logicalName)
peek := j.Peek()
- switch peek.(type) {
+ switch _context := peek.(type) {
case *elementContext:
- context := peek.(*elementContext)
- context.properties[logicalName] = value
+ _context.properties[logicalName] = value
for key, attrValue := range attr {
- context.properties[key] = attrValue
+ _context.properties[key] = attrValue
}
return nil
case *listContext:
- context := peek.(*listContext)
m := make(map[string]any)
m[logicalName] = value
for attrKey, attrValue := range attr {
m[attrKey] = attrValue
}
- context.list = append(context.list, m)
+ _context.list = append(_context.list, m)
return nil
default:
- context := &elementContext{logicalName, make(map[string]any)}
- context.properties[logicalName] = value
+ newContext := &elementContext{logicalName, make(map[string]any)}
+ newContext.properties[logicalName] = value
for key, attrValue := range attr {
- context.properties[key] = attrValue
+ newContext.properties[key] = attrValue
}
- j.Push(context)
+ j.Push(newContext)
return nil
}
}
diff --git a/plc4go/spi/values/WriteBufferPlcValueBased.go b/plc4go/spi/values/WriteBufferPlcValueBased.go
index d969023ec1..8189e00b7f 100644
--- a/plc4go/spi/values/WriteBufferPlcValueBased.go
+++ b/plc4go/spi/values/WriteBufferPlcValueBased.go
@@ -182,17 +182,15 @@ func (p *writeBufferPlcValueBased) PopContext(logicalName string, _ ...utils.Wit
pop := p.Pop()
var poppedName string
var unwrapped apiValues.PlcValue
- switch pop.(type) {
+ switch _context := pop.(type) {
case *plcValueContext:
- context := pop.(*plcValueContext)
- poppedName = context.logicalName
- unwrapped = NewPlcStruct(context.properties)
+ poppedName = _context.logicalName
+ unwrapped = NewPlcStruct(_context.properties)
case *plcListContext:
- context := pop.(*plcListContext)
- poppedName = context.logicalName
- unwrapped = NewPlcList(context.list)
+ poppedName = _context.logicalName
+ unwrapped = NewPlcList(_context.list)
default:
- panic("broken context")
+ return errors.New("broken context")
}
if poppedName != logicalName {
return errors.Errorf("unexpected closing context %s, expected %s", poppedName, logicalName)
@@ -201,13 +199,13 @@ func (p *writeBufferPlcValueBased) PopContext(logicalName string, _ ...utils.Wit
p.rootNode = NewPlcStruct(map[string]apiValues.PlcValue{logicalName: unwrapped})
return nil
}
- switch context := p.Peek().(type) {
+ switch _context := p.Peek().(type) {
case *plcValueContext:
- context.properties[logicalName] = unwrapped
+ _context.properties[logicalName] = unwrapped
case *plcListContext:
- context.list = append(context.list, NewPlcStruct(map[string]apiValues.PlcValue{logicalName: unwrapped}))
+ _context.list = append(_context.list, NewPlcStruct(map[string]apiValues.PlcValue{logicalName: unwrapped}))
default:
- panic("broken context")
+ return errors.New("broken context")
}
return nil
}
@@ -219,19 +217,17 @@ func (p *writeBufferPlcValueBased) GetPlcValue() apiValues.PlcValue {
func (p *writeBufferPlcValueBased) appendValue(logicalName string, value apiValues.PlcValue) error {
logicalName = p.SanitizeLogicalName(logicalName)
peek := p.Peek()
- switch peek.(type) {
+ switch _context := peek.(type) {
case *plcValueContext:
- context := peek.(*plcValueContext)
- context.properties[logicalName] = value
+ _context.properties[logicalName] = value
return nil
case *plcListContext:
- context := peek.(*plcListContext)
- context.list = append(context.list, value)
+ _context.list = append(_context.list, value)
return nil
default:
- context := &plcValueContext{logicalName, make(map[string]apiValues.PlcValue)}
- context.properties[logicalName] = value
- p.Push(context)
+ newContext := &plcValueContext{logicalName, make(map[string]apiValues.PlcValue)}
+ newContext.properties[logicalName] = value
+ p.Push(newContext)
return nil
}
}
[plc4x] 02/03: feat(plc4go/spi): implement GetConnectionUrl for options
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit ab8bfd8a17acf890e77f779b3dec6ec230f63ac3
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue May 2 18:35:25 2023 +0200
feat(plc4go/spi): implement GetConnectionUrl for options
---
plc4go/spi/model/DefaultPlcDiscoveryItem.go | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/plc4go/spi/model/DefaultPlcDiscoveryItem.go b/plc4go/spi/model/DefaultPlcDiscoveryItem.go
index d8393d9609..6f8e08bfb7 100644
--- a/plc4go/spi/model/DefaultPlcDiscoveryItem.go
+++ b/plc4go/spi/model/DefaultPlcDiscoveryItem.go
@@ -20,9 +20,11 @@
package model
import (
+ "net/url"
+ "strings"
+
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
- "net/url"
)
//go:generate go run ../../tools/plc4xgenerator/gen.go -type=DefaultPlcDiscoveryItem
@@ -78,8 +80,15 @@ func (d *DefaultPlcDiscoveryItem) GetAttributes() map[string]apiValues.PlcValue
}
func (d *DefaultPlcDiscoveryItem) GetConnectionUrl() string {
+ options := ""
if d.Options != nil {
- panic("Not implemented")
+ flatOptions := []string{}
+ for k, vl := range d.Options {
+ for _, v := range vl {
+ flatOptions = append(flatOptions, url.QueryEscape(k)+"="+url.QueryEscape(v))
+ }
+ }
+ options += "?" + strings.Join(flatOptions, "&")
}
- return d.ProtocolCode + ":" + d.TransportCode + "//" + d.TransportUrl.Host
+ return d.ProtocolCode + ":" + d.TransportCode + "//" + d.TransportUrl.Host + options
}
[plc4x] 01/03: test(plc4go/spi): add test for ResponseItem
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit b6910722884af51e6c58c8b3bcdbfb7a7489fcc6
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue May 2 18:18:37 2023 +0200
test(plc4go/spi): add test for ResponseItem
---
plc4go/spi/model/render_test.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/plc4go/spi/model/render_test.go b/plc4go/spi/model/render_test.go
index d25df0a66b..dac540dbef 100644
--- a/plc4go/spi/model/render_test.go
+++ b/plc4go/spi/model/render_test.go
@@ -65,6 +65,7 @@ func TestRenderTest(t *testing.T) {
&DefaultPlcWriteRequest{DefaultPlcTagRequest: NewDefaultPlcTagRequest(nil, nil)},
&DefaultPlcWriteRequestResult{},
&DefaultPlcWriteResponse{},
+ &ResponseItem{},
}
for _, sut := range suts {
t.Run(fmt.Sprintf("%T", sut), func(t *testing.T) {