mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
78a29d782b
* Switch to service key for CPI GetMplStatus Introduces read method for service key files, mock utils and tests. * Use secret text instead of file * Change serviceKey definition * Update cpiUpload to use Service Key retrieved the host and uaa information from service key * Update cpiDeploy to use service key retrieved the host and uaa information from service key * Update cpiServiceEndpoint to use Service Key retrieved the host and uaa information from service key * Update cpiDownload to use Service Key retrieved the host and uaa information from service key * Update cpiUpdateConfig to use Service Key retrieved the host and uaa information from service key * Refactor serviceKey var name * Fixed references to service key to follow the real format they should be accessed through oauth instead of uaa because of the format of the json * Rename ServiceKey to APIServiceKey To support having a different service key(and for readability), we need to change the name to API. * Add STAGES and STEPS yaml add in to each yaml file of cpi integration * Revert "Add STAGES and STEPS yaml" This reverts commit aa2665d158b0f864cfee95ff999a7dc8ea3477f1. * Change comments/formatting commonUtils Make comments more understandable and follow code climate suggestions * Change documentation files for steps remove OAuth and host and change credentials to be servicekey Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com> Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
104 lines
3.5 KiB
Go
104 lines
3.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type integrationArtifactUpdateConfigurationMockUtils struct {
|
|
*mock.ExecMockRunner
|
|
}
|
|
|
|
func newIntegrationArtifactUpdateConfigurationTestsUtils() integrationArtifactUpdateConfigurationMockUtils {
|
|
utils := integrationArtifactUpdateConfigurationMockUtils{
|
|
ExecMockRunner: &mock.ExecMockRunner{},
|
|
}
|
|
return utils
|
|
}
|
|
|
|
func TestRunIntegrationArtifactUpdateConfiguration(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("Successfully update of Integration Flow configuration parameter test", func(t *testing.T) {
|
|
apiServiceKey := `{
|
|
"oauth": {
|
|
"url": "https://demo",
|
|
"clientid": "demouser",
|
|
"clientsecret": "******",
|
|
"tokenurl": "https://demo/oauth/token"
|
|
}
|
|
}`
|
|
config := integrationArtifactUpdateConfigurationOptions{
|
|
APIServiceKey: apiServiceKey,
|
|
IntegrationFlowID: "flow1",
|
|
IntegrationFlowVersion: "1.0.1",
|
|
ParameterKey: "myheader",
|
|
ParameterValue: "def",
|
|
}
|
|
|
|
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Positive", Method: "PUT", URL: "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')"}
|
|
|
|
err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient)
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
t.Run("check url", func(t *testing.T) {
|
|
assert.Equal(t, "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')/$links/Configurations('myheader')", httpClient.URL)
|
|
})
|
|
|
|
t.Run("check method", func(t *testing.T) {
|
|
assert.Equal(t, "PUT", httpClient.Method)
|
|
})
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("Failed case of Integration Flow configuration parameter Test", func(t *testing.T) {
|
|
apiServiceKey := `{
|
|
"oauth": {
|
|
"url": "https://demo",
|
|
"clientid": "demouser",
|
|
"clientsecret": "******",
|
|
"tokenurl": "https://demo/oauth/token"
|
|
}
|
|
}`
|
|
config := integrationArtifactUpdateConfigurationOptions{
|
|
APIServiceKey: apiServiceKey,
|
|
IntegrationFlowID: "flow1",
|
|
IntegrationFlowVersion: "1.0.1",
|
|
ParameterKey: "myheader",
|
|
ParameterValue: "def",
|
|
}
|
|
|
|
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Negative"}
|
|
|
|
err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient)
|
|
assert.EqualError(t, err, "HTTP \"PUT\" request to \"https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')/$links/Configurations('myheader')\" failed with error: Not found - either wrong version for the given Id or wrong parameter key")
|
|
})
|
|
|
|
t.Run("Failed case of Integration Flow configuration parameter test with error body", func(t *testing.T) {
|
|
apiServiceKey := `{
|
|
"oauth": {
|
|
"url": "https://demo",
|
|
"clientid": "demouser",
|
|
"clientsecret": "******",
|
|
"tokenurl": "https://demo/oauth/token"
|
|
}
|
|
}`
|
|
config := integrationArtifactUpdateConfigurationOptions{
|
|
APIServiceKey: apiServiceKey,
|
|
IntegrationFlowID: "flow1",
|
|
IntegrationFlowVersion: "1.0.1",
|
|
ParameterKey: "myheader",
|
|
ParameterValue: "def",
|
|
}
|
|
|
|
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Negative_With_ResponseBody"}
|
|
|
|
err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient)
|
|
assert.EqualError(t, err, "Failed to update the integration flow configuration parameter, Response Status code: 400")
|
|
})
|
|
}
|