From dd0cc5a23e5fc9ded66a8cfa05f87c830fbaf9b4 Mon Sep 17 00:00:00 2001 From: Dimiter Georgiev Date: Mon, 14 Nov 2022 16:10:37 +0200 Subject: [PATCH] [#44] Use a common code function call Signed-off-by: Dimiter Georgiev --- integration/connector_test.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/integration/connector_test.go b/integration/connector_test.go index 9914610..ed3e861 100644 --- a/integration/connector_test.go +++ b/integration/connector_test.go @@ -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" @@ -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") @@ -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") @@ -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() -}