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