Skip to content

Commit

Permalink
Provide integration tests via the key Ditto features - ContainerFactory
Browse files Browse the repository at this point in the history
[eclipse-kanto#70] Provide integration tests via the key Ditto features - ContainerFactory
- change the github.com/stretchr/testify version to 1.8.1
- improve some method and variable names
- in case of error the test has to failed, not only log the error

Signed-off-by: Guzgunova Antonia <Antonia.Guzgunova@bosch.io>
  • Loading branch information
antoniyatrifonova authored and konstantina-gramatova committed Dec 16, 2022
1 parent 09f1292 commit 780c820
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/sylvia7788/contextcheck v1.0.4/go.mod h1:vuPKJMQ7MQ91ZTqfdyreNKwZjyUg6KO+IebVyQDedZQ=
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
Expand Down
12 changes: 6 additions & 6 deletions integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const (
ctrFactoryFeatureID = "ContainerFactory"
)

func (suite *containerManagementSuite) connect() {
func (suite *containerManagementSuite) setup() {
cfg := &testConfig{}

suite.T().Log(getConfigHelp(*cfg))
Expand Down Expand Up @@ -112,13 +112,13 @@ func (suite *containerManagementSuite) connect() {
suite.ctrThingID = edgeDeviceCfg.DeviceID + ":edge:containers"
suite.ctrThingURL = fmt.Sprintf("%s/api/2/things/%s", strings.TrimSuffix(cfg.DigitalTwinAPIAddress, "/"), suite.ctrThingID)
suite.ctrFactoryFeatureURL = fmt.Sprintf("%s/features/%s", suite.ctrThingURL, ctrFactoryFeatureID)
namespaceID := model.NewNamespacedIDFrom(suite.ctrThingID)
suite.topicCreated = fmt.Sprintf("%s/%s/things/twin/events/created", namespaceID.Namespace, namespaceID.Name)
suite.topicModify = fmt.Sprintf("%s/%s/things/twin/events/modified", namespaceID.Namespace, namespaceID.Name)
suite.topicDeleted = fmt.Sprintf("%s/%s/things/twin/events/deleted", namespaceID.Namespace, namespaceID.Name)
ctrThingID := model.NewNamespacedIDFrom(suite.ctrThingID)
suite.topicCreated = fmt.Sprintf("%s/%s/things/twin/events/created", ctrThingID.Namespace, ctrThingID.Name)
suite.topicModify = fmt.Sprintf("%s/%s/things/twin/events/modified", ctrThingID.Namespace, ctrThingID.Name)
suite.topicDeleted = fmt.Sprintf("%s/%s/things/twin/events/deleted", ctrThingID.Namespace, ctrThingID.Name)
}

func (suite *containerManagementSuite) disconnect() {
func (suite *containerManagementSuite) tearDown() {
suite.dittoClient.Disconnect()
suite.mqttClient.Disconnect(uint(suite.cfg.MqttQuiesceMs))
}
Expand Down
14 changes: 7 additions & 7 deletions integration/containerfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ctrFactorySuite struct {
}

func (suite *ctrFactorySuite) SetupSuite() {
suite.connect()
suite.setup()
ctrFactoryFeature := suite.getCtrFeature(ctrFactoryFeatureID)
require.NotNil(suite.T(), ctrFactoryFeature, "ContainerFactory feature must not be nil")

Expand All @@ -55,7 +55,7 @@ func (suite *ctrFactorySuite) TearDownSuite() {
require.True(suite.T(), suite.awaitChan(chEvent), "event for deleting feature not received")
}
}
suite.disconnect()
suite.tearDown()
}

func TestContainerFactorySuite(t *testing.T) {
Expand All @@ -73,7 +73,7 @@ func (suite *ctrFactorySuite) TestCreateOperation() {

require.True(suite.T(), suite.awaitChan(chEvent), "event for creating feature not received")
ctrFeatureIDs = append(ctrFeatureIDs, suite.ctrFeatureID)
require.Equal(suite.T(), statusRunning, suite.getActualCtrState(), "container state is not expected")
require.Equal(suite.T(), statusRunning, suite.getActualCtrStatus(), "container status is not expected")

chEvent = suite.isDeleted()
suite.execRemoveCommand(suite.ctrFeatureID)
Expand All @@ -93,7 +93,7 @@ func (suite *ctrFactorySuite) TestCreateWithConfigOperation() {

require.True(suite.T(), suite.awaitChan(chEvent), "event for creating feature not received")
ctrFeatureIDs = append(ctrFeatureIDs, suite.ctrFeatureID)
require.Equal(suite.T(), statusRunning, suite.getActualCtrState(), "container state is not expected")
require.Equal(suite.T(), statusRunning, suite.getActualCtrStatus(), "container status is not expected")

chEvent = suite.isDeleted()
suite.execRemoveCommand(suite.ctrFeatureID)
Expand Down Expand Up @@ -125,7 +125,7 @@ func (suite *ctrFactorySuite) TestCreateWithConfigPortMapping() {

body, err := suite.doRequest(http.MethodGet, requestURL, nil)
if err != nil {
suite.T().Logf("error while getting the requested URL: %v", err)
suite.T().Errorf("error while getting the requested URL: %v", err)
}

require.Equal(suite.T(), httpResponse, string(body), "HTTP response is not expected")
Expand Down Expand Up @@ -165,11 +165,11 @@ func (suite *ctrFactorySuite) isDeleted() chan bool {
})
}

func (suite *ctrFactorySuite) getActualCtrState() string {
func (suite *ctrFactorySuite) getActualCtrStatus() string {
ctrPropertyPath := fmt.Sprintf("%s/features/%s/properties/status/state/status", suite.ctrThingURL, suite.ctrFeatureID)
body, err := suite.doRequest(http.MethodGet, ctrPropertyPath, nil)
if err != nil {
suite.T().Logf("error while getting the container feature property status: %v", err)
suite.T().Errorf("error while getting the container feature property status: %v", err)
}
return strings.Trim(string(body), "\"")
}
18 changes: 9 additions & 9 deletions integration/request_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ func (suite *containerManagementSuite) beginWSWait(ws *websocket.Conn, check fun
func (suite *containerManagementSuite) execCreateCommand(command string, params map[string]interface{}) {
url := fmt.Sprintf("%s/inbox/messages/%s", suite.ctrFactoryFeatureURL, command)
if _, err := suite.doRequest(http.MethodPost, url, &requestBody{params: params}); err != nil {
suite.T().Logf("error while creating container feature: %v", err)
suite.T().Errorf("error while creating container feature: %v", err)
}

}

func (suite *containerManagementSuite) execRemoveCommand(containerID string) {
containerURL := fmt.Sprintf("%s/features/%s", suite.ctrThingURL, containerID)
url := fmt.Sprintf("%s/inbox/messages/remove", containerURL)
func (suite *containerManagementSuite) execRemoveCommand(ctrFeatureID string) {
ctrFeatureURL := fmt.Sprintf("%s/features/%s", suite.ctrThingURL, ctrFeatureID)
url := fmt.Sprintf("%s/inbox/messages/remove", ctrFeatureURL)
if _, err := suite.doRequest(http.MethodPost, url, &requestBody{param: "true"}); err != nil {
suite.T().Logf("error while removing container feature: %v", err)
suite.T().Errorf("error while removing container feature: %v", err)
}
}

Expand Down Expand Up @@ -232,18 +232,18 @@ func (suite *containerManagementSuite) awaitChan(ch chan bool) bool {
}
}

func (suite *containerManagementSuite) getCtrFeature(containerID string) model.Feature {
ctrThingURL := fmt.Sprintf("%s/features/%s", suite.ctrThingURL, containerID)
func (suite *containerManagementSuite) getCtrFeature(ctrFeatureID string) model.Feature {
ctrThingURL := fmt.Sprintf("%s/features/%s", suite.ctrThingURL, ctrFeatureID)
body, err := suite.doRequest(http.MethodGet, ctrThingURL, nil)

if err != nil {
suite.T().Logf("error while getting the container feature: %v", err)
suite.T().Errorf("error while getting the container feature: %v", err)
}

var containerFeature = &containerFeature{}
json.Unmarshal(body, &containerFeature)

return client.NewFeature(containerID,
return client.NewFeature(ctrFeatureID,
client.WithFeatureDefinition(client.NewDefinitionIDFromString(containerFeature.Definition[0])),
client.WithFeatureProperties(containerFeature.Properties))
}

0 comments on commit 780c820

Please sign in to comment.