2020-09-18 11:18:51 +02:00
|
|
|
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
|
2021-11-12 15:33:18 +02:00
|
|
|
config := abapAddonAssemblyKitCreateTargetVectorOptions{
|
|
|
|
Username: "dummy",
|
|
|
|
Password: "dummy",
|
|
|
|
}
|
2020-09-18 11:18:51 +02:00
|
|
|
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{}
|
2022-07-06 14:29:04 +02:00
|
|
|
err = json.Unmarshal([]byte(cpe.abap.addonDescriptor), &resultAddonDescriptor)
|
|
|
|
assert.NoError(t, err)
|
2020-09-18 11:18:51 +02:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|