1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-06 04:13:55 +02:00
sap-jenkins-library/pkg/abap/aakaas/aakUtils_mock.go
rosemarieB e6c5c8a72f
Abap refactoring (#3340)
* Update abapAddonAssemblyKitReleasePackages.go

* add error handling for initAAKaaS

* runtime to config, url.QueryEscape, check return body

* Update abapAddonAssemblyKitCheckCVs_test.go

* add log entrys for testing

* correct yaml

* change unmarshal logic

* Update abapAddonAssemblyKitCheckPV_test.go

* adding utils functionality

* Update bfw_test.go

* reset CheckPV

* reset CheckCVs

* reset ReserveNextPackages

* set back CheckPV and CheckCVs

* moving mock

* renaming

* renaming

* moving mocking to checkCVs test

* fixing unittests

* trying mock with comment

* referencing unittest to mockfile

* Update abapAddonAssemblyKitCheckCVs.go

* Update cmd/abapAddonAssemblyKitCheckPV.go

Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>

* Update cmd/abapAddonAssemblyKitReleasePackages.go

Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>

* Update cmd/abapAddonAssemblyKitPublishTargetVector.go

Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>

* Update cmd/abapAddonAssemblyKitReserveNextPackages.go

Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>

* fixing unittests

* fixing mock comment

Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>
2021-12-09 12:54:18 +01:00

132 lines
3.0 KiB
Go

//go:build !release
// +build !release
package aakaas
import (
"time"
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
"github.com/SAP/jenkins-library/pkg/abaputils"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/pkg/errors"
)
type AakBundleMock struct {
*mock.ExecMockRunner
*abaputils.ClientMock
maxRuntime time.Duration
}
func NewAakBundleMock() *AakBundleMock {
utils := AakBundleMock{
ExecMockRunner: &mock.ExecMockRunner{},
ClientMock: &abaputils.ClientMock{},
maxRuntime: 1 * time.Second,
}
return &utils
}
func (bundle *AakBundleMock) GetUtils() AakUtils {
return bundle
}
func (bundle *AakBundleMock) GetMaxRuntime() time.Duration {
return bundle.maxRuntime
}
func (bundle *AakBundleMock) SetMaxRuntime(maxRuntime time.Duration) {
bundle.maxRuntime = maxRuntime
}
func (bundle *AakBundleMock) GetPollingInterval() time.Duration {
return 1 * time.Microsecond
}
func (bundle *AakBundleMock) SetBodyList(bodyList []string) {
bundle.ClientMock.Body = ""
bundle.ClientMock.BodyList = bodyList
}
func (bundle *AakBundleMock) SetBody(body string) {
bundle.ClientMock.Body = body
bundle.ClientMock.BodyList = []string{}
}
func (bundle *AakBundleMock) SetError(errorText string) {
bundle.ClientMock.Error = errors.New(errorText)
}
func (bundle *AakBundleMock) ReadAddonDescriptor(FileName string) (abaputils.AddonDescriptor, error) {
var addonDescriptor abaputils.AddonDescriptor
var err error
switch FileName {
case "success":
{
addonDescriptor = abaputils.AddonDescriptor{
AddonProduct: "/DRNMSPC/PRD01",
AddonVersionYAML: "3.2.1",
Repositories: []abaputils.Repository{
{
Name: "/DRNMSPC/COMP01",
VersionYAML: "1.2.3",
CommitID: "HUGO1234",
},
},
}
}
case "noCommitID":
{
addonDescriptor = abaputils.AddonDescriptor{
AddonProduct: "/DRNMSPC/PRD01",
AddonVersionYAML: "3.2.1",
Repositories: []abaputils.Repository{
{
Name: "/DRNMSPC/COMP01",
VersionYAML: "1.2.3",
},
},
}
}
case "failing":
{
err = errors.New("error in ReadAddonDescriptor")
}
}
return addonDescriptor, err
}
//*****************************other client mock *******************************
type AakBundleMockNewMC struct {
*mock.ExecMockRunner
*abapbuild.MockClient
maxRuntime time.Duration
}
func NewAakBundleMockNewMC(mC *abapbuild.MockClient) *AakBundleMockNewMC {
utils := AakBundleMockNewMC{
ExecMockRunner: &mock.ExecMockRunner{},
MockClient: mC,
maxRuntime: 1 * time.Second,
}
return &utils
}
func (bundle *AakBundleMockNewMC) GetUtils() AakUtils {
return bundle
}
func (bundle *AakBundleMockNewMC) GetMaxRuntime() time.Duration {
return bundle.maxRuntime
}
func (bundle *AakBundleMockNewMC) GetPollingInterval() time.Duration {
return 1 * time.Microsecond
}
func (bundle *AakBundleMockNewMC) ReadAddonDescriptor(FileName string) (abaputils.AddonDescriptor, error) {
var addonDescriptor abaputils.AddonDescriptor
err := errors.New("don't use this")
return addonDescriptor, err
}