Skip to content

Provide integration tests via the key Ditto features - SoftwareUpdatable#182

Merged
k-gostev merged 4 commits intoeclipse-kanto:mainfrom
bosch-io:su-integration-test
Aug 10, 2023
Merged

Provide integration tests via the key Ditto features - SoftwareUpdatable#182
k-gostev merged 4 commits intoeclipse-kanto:mainfrom
bosch-io:su-integration-test

Conversation

@antonia-avramova
Copy link
Contributor

[#65] Provide integration tests via the key Ditto features - SoftwareUpdatable

Signed-off-by: Antonia Avramova [email protected]

@k-gostev k-gostev linked an issue Aug 4, 2023 that may be closed by this pull request
@k-gostev k-gostev self-requested a review August 4, 2023 06:42
Copy link
Contributor

@k-gostev k-gostev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks very good, I have just a couple of nits

Comment on lines +26 to +37
"testing"

"os"
"strings"

"github.com/eclipse-kanto/container-management/rollouts/api/datatypes"
"github.com/eclipse-kanto/kanto/integration/util"
"github.com/eclipse/ditto-clients-golang/protocol"
"github.com/google/uuid"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"testing"
"os"
"strings"
"github.com/eclipse-kanto/container-management/rollouts/api/datatypes"
"github.com/eclipse-kanto/kanto/integration/util"
"github.com/eclipse/ditto-clients-golang/protocol"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"testing"
"os"
"strings"
"github.com/eclipse-kanto/container-management/rollouts/api/datatypes"
"github.com/eclipse-kanto/kanto/integration/util"
"github.com/eclipse/ditto-clients-golang/protocol"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

actionInstall = "install"
paramCorID = "correlationId"
paramForced = "forced"
validJSONUrl = "https://raw.githubusercontent.com/eclipse-kanto/container-management/main/containerm/pkg/testutil/config/container/valid.json"
Copy link
Contributor

@k-gostev k-gostev Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per https://github.com/golang/go/wiki/CodeReviewComments#initialisms

Suggested change
validJSONUrl = "https://raw.githubusercontent.com/eclipse-kanto/container-management/main/containerm/pkg/testutil/config/container/valid.json"
validContainerURL = "https://raw.githubusercontent.com/eclipse-kanto/container-management/main/containerm/pkg/testutil/config/container/valid.json"

}

const (
suFeatureID = "SoftwareUpdatable"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use this constant instead


suite.swUpdatableFeatureURL = util.GetFeatureURL(suite.ctrThingURL, suFeatureID)

suite.assertCtrFeatureDefinition(suite.swUpdatableFeatureURL, "[\"org.eclipse.hawkbit.swupdatable:SoftwareUpdatable:2.0.0\"]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please export the necessary constants from here and reuse them.

Comment on lines +73 to +75
filter := fmt.Sprintf("like(resource:path,'/features/%s*')", suFeatureID)

err := util.SubscribeForWSMessages(suite.Cfg, wsConnection, util.StartSendEvents, filter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
filter := fmt.Sprintf("like(resource:path,'/features/%s*')", suFeatureID)
err := util.SubscribeForWSMessages(suite.Cfg, wsConnection, util.StartSendEvents, filter)
err := util.SubscribeForWSMessages(suite.Cfg, wsConnection, util.StartSendEvents, fmt.Sprintf("like(resource:path,'/features/%s*')", suFeatureID)

err = util.ProcessWSMessages(suite.Cfg, wsConnection, func(event *protocol.Envelope) (bool, error) {
var err error
if event.Topic.String() == suite.topicModified {
if event.Path == fmt.Sprintf("/features/%s/properties/status/lastOperation", suFeatureID) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/features/%s/properties/status/ is quite repetitive, could you create a function constructStatusPath(featureID, property string) that constructs the status and use it instead.

Comment on lines +244 to +245
err = suite.removeContainer(createRemoveParams(ctrID))
require.NoError(suite.T(), err, "failed to process removing the container")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = suite.removeContainer(createRemoveParams(ctrID))
require.NoError(suite.T(), err, "failed to process removing the container")
require.NoError(suite.T(), suite.removeContainer(createRemoveParams(ctrID)), "failed to process removing the container")

Comment on lines +268 to +269
err := suite.removeContainer(createRemoveParams(ctrID))
require.ErrorContains(suite.T(), err, "container with ID = "+ctrID+" does not exist")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err := suite.removeContainer(createRemoveParams(ctrID))
require.ErrorContains(suite.T(), err, "container with ID = "+ctrID+" does not exist")
require.ErrorContains(suite.T(), suite.removeContainer(createRemoveParams(ctrID)), "container with ID = "+ctrID+" does not exist")

Comment on lines +277 to +283
err = os.WriteFile(filePath, src, 7777)
require.NoError(suite.T(), err, "unable to write file with path "+filePath)

params := createInstallParams(filePath, src, wrongChecksum)
err = os.Remove(filePath)
require.NoError(suite.T(), err, "unable to remove file with path "+filePath)
return params
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you try this way?

Suggested change
err = os.WriteFile(filePath, src, 7777)
require.NoError(suite.T(), err, "unable to write file with path "+filePath)
params := createInstallParams(filePath, src, wrongChecksum)
err = os.Remove(filePath)
require.NoError(suite.T(), err, "unable to remove file with path "+filePath)
return params
require.NoError(suite.T(), os.WriteFile(filePath, src, 7777), "unable to write file with path "+filePath)
defer require.NoError(suite.T(), os.Remove(filePath), "unable to remove file with path "+filePath)
return createInstallParams(filePath, src, wrongChecksum)

Comment on lines +361 to +362
err = json.Unmarshal(bytes, &ctrImage)
return fileStat, ctrImage, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = json.Unmarshal(bytes, &ctrImage)
return fileStat, ctrImage, err
err =
return fileStat, ctrImage, json.Unmarshal(bytes, &ctrImage)

Comment on lines +327 to +332
"software": []*datatypes.DependencyDescription{
&datatypes.DependencyDescription{
Name: ctrID,
},
},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"software": []*datatypes.DependencyDescription{
&datatypes.DependencyDescription{
Name: ctrID,
},
},
}
"software": []*datatypes.DependencyDescription{
{
Name: ctrID,
},
},
}

require.NoError(suite.T(), err, "failed to subscribe for the %s messages", util.StartSendEvents)

_, err = util.ExecuteOperation(suite.Cfg, suite.suFeatureURL, "remove", params)
suite.closeOnError(wsConnection, err, "failed to execute software updatable install for containers with params %v", params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
suite.closeOnError(wsConnection, err, "failed to execute software updatable install for containers with params %v", params)
suite.closeOnError(wsConnection, err, "failed to execute software updatable remove for containers with params %v", params)

wsConnection.Close()
}
require.Errorf(suite.T(), err, "failed to execute software updatable install for containers with params %v", params)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +362 to +365
if err != nil {
return nil, err
}
defer response.Body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err != nil {
return nil, err
}
defer response.Body.Close()
if err != nil {
return nil, err
}
if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusMultipleChoices {
return nil, fmt.Errorf("http status code is not in the 2xx range: %v", response.StatusCode)
}
defer response.Body.Close()

Comment on lines +271 to +286
func (suite *softwareUpdatableSuite) createParameters(wrongChecksum bool) map[string]interface{} {
src, err := download(validContainerURL)
require.NoError(suite.T(), err, "unable to download file from url "+validContainerURL)
splitStr := strings.Split(validContainerURL, "/")
filePath := "/tmp/" + splitStr[len(splitStr)-1]
require.NoError(suite.T(), os.WriteFile(filePath, src, 7777), "unable to write file with path "+filePath)

defer require.NoError(suite.T(), os.Remove(filePath), "unable to remove file with path "+filePath)
return createInstallParams(filePath, src, wrongChecksum)
}

func createInstallParams(filePath string, src []byte, wrongChecksum bool) map[string]interface{} {
fileInfo, ctrStruct, err := getCtrImageStructure(filePath)
if err != nil {
return make(map[string]interface{})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of some error related to the file operations the test will fail in a not a user friendly manner

Suggested change
func (suite *softwareUpdatableSuite) createParameters(wrongChecksum bool) map[string]interface{} {
src, err := download(validContainerURL)
require.NoError(suite.T(), err, "unable to download file from url "+validContainerURL)
splitStr := strings.Split(validContainerURL, "/")
filePath := "/tmp/" + splitStr[len(splitStr)-1]
require.NoError(suite.T(), os.WriteFile(filePath, src, 7777), "unable to write file with path "+filePath)
defer require.NoError(suite.T(), os.Remove(filePath), "unable to remove file with path "+filePath)
return createInstallParams(filePath, src, wrongChecksum)
}
func createInstallParams(filePath string, src []byte, wrongChecksum bool) map[string]interface{} {
fileInfo, ctrStruct, err := getCtrImageStructure(filePath)
if err != nil {
return make(map[string]interface{})
}
func (suite *softwareUpdatableSuite) createParameters(wrongChecksum bool) map[string]interface{} {
src, err := download(validContainerURL)
require.NoError(suite.T(), err, fmt.Sprintf("unable to download file from url %s", validContainerURL))
filePath := "valid.json"
require.NoError(suite.T(), os.WriteFile(filePath, src, 0755), "unable to write file with path "+filePath)
fileInfo, ctrStruct, err := getCtrImageStructure(filePath)
require.NoError(suite.T(), err, "unable to create container image struct")
defer require.NoError(suite.T(), os.Remove(filePath), "unable to remove file with path "+filePath)
return createInstallParams(fileInfo, ctrStruct, src, wrongChecksum)
}
func createInstallParams(fileInfo fs.FileInfo, ctrStruct CtrImageStruct, src []byte, wrongChecksum bool) map[string]interface{} {
splitStr := strings.Split(ctrStruct.Image.Name, "/")
swModuleStr := strings.Split(splitStr[len(splitStr)-1], ":")

@k-gostev k-gostev merged commit b0e35dc into eclipse-kanto:main Aug 10, 2023
@k-gostev k-gostev deleted the su-integration-test branch August 10, 2023 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide integration tests via the key Ditto features - SoftwareUpdatable

2 participants