1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/abapAddonAssemblyKitCheckPV_test.go
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

48 lines
1.6 KiB
Go

//go:build unit
// +build unit
package cmd
import (
"encoding/json"
"testing"
"github.com/SAP/jenkins-library/pkg/abap/aakaas"
"github.com/SAP/jenkins-library/pkg/abaputils"
"github.com/stretchr/testify/assert"
)
func TestCheckPVStep(t *testing.T) {
var config abapAddonAssemblyKitCheckPVOptions
var cpe abapAddonAssemblyKitCheckPVCommonPipelineEnvironment
bundle := aakaas.NewAakBundleMock()
bundle.SetBody(aakaas.ResponseCheckPV)
utils := bundle.GetUtils()
config.Username = "dummyUser"
config.Password = "dummyPassword"
t.Run("step success", func(t *testing.T) {
config.AddonDescriptorFileName = "success"
err := runAbapAddonAssemblyKitCheckPV(&config, nil, utils, &cpe)
assert.NoError(t, err, "Did not expect error")
var addonDescriptorFinal abaputils.AddonDescriptor
err = json.Unmarshal([]byte(cpe.abap.addonDescriptor), &addonDescriptorFinal)
assert.NoError(t, err)
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"
err := runAbapAddonAssemblyKitCheckPV(&config, nil, utils, &cpe)
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"
bundle.SetBody("ErrorBody")
bundle.SetError("error during validation")
err := runAbapAddonAssemblyKitCheckPV(&config, nil, utils, &cpe)
assert.Error(t, err, "Did expect error")
})
}