1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/abapAddonAssemblyKitPublishTargetVector_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

88 lines
2.3 KiB
Go

//go:build unit
// +build unit
package cmd
import (
"encoding/json"
"testing"
"github.com/SAP/jenkins-library/pkg/abap/aakaas"
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
"github.com/SAP/jenkins-library/pkg/abaputils"
"github.com/stretchr/testify/assert"
)
func TestPublishTargetVectorStep(t *testing.T) {
//setup
config := abapAddonAssemblyKitPublishTargetVectorOptions{
TargetVectorScope: "P",
Username: "dummy",
Password: "dummy",
}
addonDescriptor := abaputils.AddonDescriptor{
TargetVectorID: "W7Q00207512600000353",
}
adoDesc, _ := json.Marshal(addonDescriptor)
config.AddonDescriptor = string(adoDesc)
t.Run("step success prod", func(t *testing.T) {
//arrange
mc := abapbuild.NewMockClient()
mc.AddData(aakaas.AAKaaSHead)
mc.AddData(aakaas.AAKaaSTVPublishProdPost)
mc.AddData(aakaas.AAKaaSGetTVPublishRunning)
mc.AddData(aakaas.AAKaaSGetTVPublishProdSuccess)
bundle := aakaas.NewAakBundleMockNewMC(&mc)
utils := bundle.GetUtils()
//act
err := runAbapAddonAssemblyKitPublishTargetVector(&config, nil, &utils)
//assert
assert.NoError(t, err, "Did not expect error")
})
t.Run("step success test", func(t *testing.T) {
//arrange
config.TargetVectorScope = "T"
mc := abapbuild.NewMockClient()
mc.AddData(aakaas.AAKaaSHead)
mc.AddData(aakaas.AAKaaSTVPublishTestPost)
mc.AddData(aakaas.AAKaaSGetTVPublishRunning)
mc.AddData(aakaas.AAKaaSGetTVPublishTestSuccess)
bundle := aakaas.NewAakBundleMockNewMC(&mc)
utils := bundle.GetUtils()
//act
err := runAbapAddonAssemblyKitPublishTargetVector(&config, nil, &utils)
//assert
assert.NoError(t, err, "Did not expect error")
})
t.Run("step fail http", func(t *testing.T) {
//arrange
bundle := aakaas.NewAakBundleMock()
bundle.SetBody("dummy")
bundle.SetError("dummy")
utils := bundle.GetUtils()
//act
err := runAbapAddonAssemblyKitPublishTargetVector(&config, nil, &utils)
//assert
assert.Error(t, err, "Must end with error")
})
t.Run("step fail no id", func(t *testing.T) {
//arrange
config := abapAddonAssemblyKitPublishTargetVectorOptions{}
mc := abapbuild.NewMockClient()
bundle := aakaas.NewAakBundleMockNewMC(&mc)
utils := bundle.GetUtils()
//act
err := runAbapAddonAssemblyKitPublishTargetVector(&config, nil, &utils)
//assert
assert.Error(t, err, "Must end with error")
})
}