1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/abapAddonAssemblyKitCreateTargetVector_test.go
tiloKo 13d1b562bf
AAKaaS: 4 create Target Vector (#2041)
* adding my steps

* messy step

* Update abapEnvironmentAssembly.go

* clean up

* change yaml

* corrections

* Update cloudFoundryDeploy.go

* update

* delete simulation step

* remove simulate

* Update PiperGoUtils.groovy

* Update PiperGoUtils.groovy

* Update CommonStepsTest.groovy

* add docu

* Update abapEnvironmentAssembly.md

* changes due to PR

* Update .gitignore

* b

* CV list

* Update abapEnvironmentAssembly.go

* testing with simulation

* Update abapEnvironmentAssembly.go

* remove simulation

* renaming

* Update mkdocs.yml

* moving service key to yaml and fixing code climate

* Update abapEnvironmentAssemblePackages.go

* Update abapEnvironmentAssemblePackages.go

* Update abapEnvironmentAssemblePackages.go

* Update abapEnvironmentAssemblePackages.go

* change input

* Update abapEnvironmentAssemblePackages.go

* change json tag

* fixed error handling

* documentation

* Update abapEnvironmentAssemblePackages.md

* Update abapEnvironmentAssemblePackages.md

* fixing code climate issues

* fixing code climate issues

* Update abapEnvironmentAssemblePackages.yaml

* fixing code climate issues

* Update abapEnvironmentAssemblePackages.yaml

* adding unittests

* adding unittests and improved logging

* yaml -> json

* change scope of cfServiceKeyName

* correct indentation

* Update CommonStepsTest.groovy

* maintain correct step order

* AAKaaS publishTV

* AAKaaS createTV

* AAKaaS createTV #2

* AAKaaS createTV #3

Co-authored-by: rosemarieB <45030247+rosemarieB@users.noreply.github.com>
Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-09-18 11:18:51 +02:00

145 lines
4.4 KiB
Go

package cmd
import (
"encoding/json"
"testing"
"github.com/SAP/jenkins-library/pkg/abaputils"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestCreateTargetVectorStep(t *testing.T) {
//setup
config := abapAddonAssemblyKitCreateTargetVectorOptions{}
addonDescriptor := abaputils.AddonDescriptor{
AddonProduct: "dummy",
AddonVersion: "dummy",
AddonSpsLevel: "dummy",
AddonPatchLevel: "dummy",
TargetVectorID: "dummy",
Repositories: []abaputils.Repository{
{
Name: "dummy",
Version: "dummy",
SpLevel: "dummy",
PatchLevel: "dummy",
PackageName: "dummy",
},
},
}
adoDesc, _ := json.Marshal(addonDescriptor)
config.AddonDescriptor = string(adoDesc)
client := &abaputils.ClientMock{
Body: responseCreateTargetVector,
}
cpe := abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment{}
t.Run("step success test", func(t *testing.T) {
//act
err := runAbapAddonAssemblyKitCreateTargetVector(&config, nil, client, &cpe)
//assert
assert.NoError(t, err, "Did not expect error")
resultAddonDescriptor := abaputils.AddonDescriptor{}
json.Unmarshal([]byte(cpe.abap.addonDescriptor), &resultAddonDescriptor)
assert.Equal(t, "W7Q00207512600000262", resultAddonDescriptor.TargetVectorID)
})
t.Run("step success test", func(t *testing.T) {
//arrange
client := &abaputils.ClientMock{
Body: responseCreateTargetVector,
Error: errors.New("dummy"),
}
//act
err := runAbapAddonAssemblyKitCreateTargetVector(&config, nil, client, &cpe)
//assert
assert.Error(t, err, "Must end with error")
})
t.Run("step error init product", func(t *testing.T) {
//arrange
addonDescriptor := abaputils.AddonDescriptor{
Repositories: []abaputils.Repository{
{},
},
}
adoDesc, _ := json.Marshal(addonDescriptor)
config.AddonDescriptor = string(adoDesc)
//act
err := runAbapAddonAssemblyKitCreateTargetVector(&config, nil, client, &cpe)
//assert
assert.Error(t, err, "Must end with error")
})
t.Run("step error init component", func(t *testing.T) {
//arrange
addonDescriptor := abaputils.AddonDescriptor{
AddonProduct: "dummy",
AddonVersion: "dummy",
AddonSpsLevel: "dummy",
AddonPatchLevel: "dummy",
TargetVectorID: "dummy",
Repositories: []abaputils.Repository{
{
Name: "dummy",
Version: "dummy",
SpLevel: "dummy",
PatchLevel: "dummy",
PackageName: "dummy",
},
{},
},
}
adoDesc, _ := json.Marshal(addonDescriptor)
config.AddonDescriptor = string(adoDesc)
//act
err := runAbapAddonAssemblyKitCreateTargetVector(&config, nil, client, &cpe)
//assert
assert.Error(t, err, "Must end with error")
})
}
var responseCreateTargetVector = `{
"d": {
"__metadata": {
"id": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorSet('W7Q00207512600000262')",
"uri": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorSet('W7Q00207512600000262')",
"type": "SSDA.AAS_ODATA_PACKAGE_SRV.TargetVector"
},
"Id": "W7Q00207512600000262",
"Vendor": "0000203069",
"ProductName": "/DRNMSPC/PRD01",
"ProductVersion": "0001",
"SpsLevel": "0000",
"PatchLevel": "0000",
"Status": "G",
"Content": {
"results": [
{
"__metadata": {
"id": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorContentSet(Id='W7Q00207512600000262',ScName='%2FDRNMSPC%2FCOMP01')",
"uri": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorContentSet(Id='W7Q00207512600000262',ScName='%2FDRNMSPC%2FCOMP01')",
"type": "SSDA.AAS_ODATA_PACKAGE_SRV.TargetVectorContent"
},
"Id": "W7Q00207512600000262",
"ScName": "/DRNMSPC/COMP01",
"ScVersion": "0001",
"DeliveryPackage": "SAPK-001AAINDRNMSPC",
"SpLevel": "0000",
"PatchLevel": "0000",
"Header": {
"__deferred": {
"uri": "https://W7Q.DMZWDF.SAP.CORP:443/odata/aas_ocs_package/TargetVectorContentSet(Id='W7Q00207512600000262',ScName='%2FDRNMSPC%2FCOMP01')/Header"
}
}
}
]
}
}
}`