2023-05-03 18:02:11 +02:00
|
|
|
//go:build unit
|
|
|
|
// +build unit
|
|
|
|
|
2020-09-17 15:56:14 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2021-12-09 13:54:18 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/abap/aakaas"
|
2020-09-17 15:56:14 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/abaputils"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckPVStep(t *testing.T) {
|
|
|
|
var config abapAddonAssemblyKitCheckPVOptions
|
|
|
|
var cpe abapAddonAssemblyKitCheckPVCommonPipelineEnvironment
|
2021-12-09 13:54:18 +02:00
|
|
|
bundle := aakaas.NewAakBundleMock()
|
2023-01-12 16:47:11 +02:00
|
|
|
bundle.SetBody(aakaas.ResponseCheckPV)
|
2021-12-09 13:54:18 +02:00
|
|
|
utils := bundle.GetUtils()
|
|
|
|
config.Username = "dummyUser"
|
|
|
|
config.Password = "dummyPassword"
|
2020-09-17 15:56:14 +02:00
|
|
|
t.Run("step success", func(t *testing.T) {
|
|
|
|
config.AddonDescriptorFileName = "success"
|
2022-08-09 10:57:02 +02:00
|
|
|
err := runAbapAddonAssemblyKitCheckPV(&config, nil, utils, &cpe)
|
2020-09-17 15:56:14 +02:00
|
|
|
assert.NoError(t, err, "Did not expect error")
|
|
|
|
var addonDescriptorFinal abaputils.AddonDescriptor
|
2022-07-06 14:29:04 +02:00
|
|
|
err = json.Unmarshal([]byte(cpe.abap.addonDescriptor), &addonDescriptorFinal)
|
|
|
|
assert.NoError(t, err)
|
2020-09-17 15:56:14 +02:00
|
|
|
assert.Equal(t, "0003", addonDescriptorFinal.AddonVersion)
|
|
|
|
assert.Equal(t, "0002", addonDescriptorFinal.AddonSpsLevel)
|
|
|
|
assert.Equal(t, "0001", addonDescriptorFinal.AddonPatchLevel)
|
|
|
|
})
|
|
|
|
t.Run("step error - in ReadAddonDescriptor", func(t *testing.T) {
|
|
|
|
config.AddonDescriptorFileName = "failing"
|
2022-08-09 10:57:02 +02:00
|
|
|
err := runAbapAddonAssemblyKitCheckPV(&config, nil, utils, &cpe)
|
2020-09-17 15:56:14 +02:00
|
|
|
assert.Error(t, err, "Did expect error")
|
|
|
|
assert.Equal(t, err.Error(), "error in ReadAddonDescriptor")
|
|
|
|
})
|
|
|
|
t.Run("step error - in validate", func(t *testing.T) {
|
|
|
|
config.AddonDescriptorFileName = "success"
|
2021-12-09 13:54:18 +02:00
|
|
|
bundle.SetBody("ErrorBody")
|
|
|
|
bundle.SetError("error during validation")
|
2022-08-09 10:57:02 +02:00
|
|
|
err := runAbapAddonAssemblyKitCheckPV(&config, nil, utils, &cpe)
|
2020-09-17 15:56:14 +02:00
|
|
|
assert.Error(t, err, "Did expect error")
|
|
|
|
})
|
|
|
|
}
|