mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
54479f7255
* new checks for commitIDs * new checks for commitIDs * relocate step from build stage to initial checks + refac * log list * fix log + check * log format * fix unit tests * targetVector refac + polling * refac * refac 2 * polling * remove debug output * remove debug output Co-authored-by: Christian Luttenberger <42861202+bluesbrother84@users.noreply.github.com>
148 lines
4.5 KiB
Go
148 lines
4.5 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{
|
|
Username: "dummy",
|
|
Password: "dummy",
|
|
}
|
|
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"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}`
|