Skip to content

Commit

Permalink
[eclipse-kanto#44] Use a common code function call
Browse files Browse the repository at this point in the history
Signed-off-by: Dimiter Georgiev <dimiter.georgiev@bosch.io>
  • Loading branch information
Dimiter Georgiev authored and e-grigorov committed Nov 25, 2022
1 parent 04e0410 commit dd0cc5a
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions integration/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
env "github.com/caarlos0/env/v6"

"github.com/eclipse-kanto/kanto/integration/util"
"github.com/eclipse/ditto-clients-golang"
"github.com/eclipse/ditto-clients-golang/model"
"github.com/eclipse/ditto-clients-golang/protocol"
"github.com/eclipse/ditto-clients-golang/protocol/things"
Expand Down Expand Up @@ -252,7 +251,7 @@ func (suite *ConnectorSuite) TestTelemetry() {
suite.testModify("t", "testTelemetry")
}

func (suite *ConnectorSuite) testModify(channel string, newValue string) {
func (suite *ConnectorSuite) testModify(topic string, newValue string) {
cfg := suite.Cfg
ws, err := util.NewDigitalTwinWSConnection(cfg)
require.NoError(suite.T(), err, "cannot create a websocket connection to the backend")
Expand All @@ -272,7 +271,7 @@ func (suite *ConnectorSuite) testModify(channel string, newValue string) {

msg := cmd.Envelope(protocol.WithResponseRequired(false))

err = suite.sendDittoEvent(channel, msg)
err = util.SendMQTTMessage(suite.Cfg, suite.MQTTClient, topic, msg)

require.NoError(suite.T(), err, "unable to send event to the backend")

Expand All @@ -292,16 +291,3 @@ func (suite *ConnectorSuite) testModify(channel string, newValue string) {

assert.Equal(suite.T(), fmt.Sprintf("\"%s\"", newValue), strings.TrimSpace(string(body)), "property value updated")
}

func (suite *ConnectorSuite) sendDittoEvent(topic string, message interface{}) error {
payload, err := json.Marshal(message)
if err != nil {
return err
}
token := suite.MQTTClient.Publish(topic, 1, false, payload)
timeout := util.MillisToDuration(suite.Cfg.MqttAcknowledgeTimeoutMs)
if !token.WaitTimeout(timeout) {
return ditto.ErrAcknowledgeTimeout
}
return token.Error()
}

0 comments on commit dd0cc5a

Please sign in to comment.