From 0ca2f72699f112ba6889133d123475c7ef6637e8 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:40:35 +0200 Subject: [PATCH 1/5] chore(mockery): add mockery configuration (#4941) * update mockery config * update mockery config * rename mockery config * update existing mocks * update mockery config * update mockery config * move cmd mocks to cmd pkg * add hadolint mocks to config * use moved files * remove comment --- .mockery.yaml => .mockery.yml | 27 ++- cmd/githubPublishRelease.go | 1 - cmd/hadolintExecute.go | 2 - cmd/hadolintExecute_test.go | 2 +- cmd/mocks/GithubRepoClient.go | 234 +++++++++++++++++- cmd/mocks/hadolintClient.go | 119 +++++++++ cmd/mocks/hadolintPiperFileUtils.go | 188 +++++++++++++++ pkg/config/mocks/vaultClient.go | 2 +- pkg/hadolint/mocks/hadolintClient.go | 34 --- pkg/hadolint/mocks/hadolintPiperFileUtils.go | 62 ----- pkg/influx/mocks/Client.go | 2 +- pkg/influx/mocks/WriteAPIBlocking.go | 2 +- pkg/jenkins/artifact.go | 1 - pkg/jenkins/build.go | 1 - pkg/jenkins/credential.go | 1 - pkg/jenkins/jenkins.go | 1 - pkg/jenkins/job.go | 1 - pkg/jenkins/mocks/Artifact.go | 168 ++++++++++++- pkg/jenkins/mocks/Build.go | 132 +++++++++- pkg/jenkins/mocks/CredentialsManager.go | 59 ++++- pkg/jenkins/mocks/Jenkins.go | 135 ++++++++++- pkg/jenkins/mocks/Job.go | 130 +++++++++- pkg/jenkins/mocks/Task.go | 166 ++++++++++++- pkg/jenkins/task.go | 1 - pkg/kubernetes/mocks/HelmExecutor.go | 239 ++++++++++++++++++- 25 files changed, 1562 insertions(+), 148 deletions(-) rename .mockery.yaml => .mockery.yml (51%) create mode 100644 cmd/mocks/hadolintClient.go create mode 100644 cmd/mocks/hadolintPiperFileUtils.go delete mode 100644 pkg/hadolint/mocks/hadolintClient.go delete mode 100644 pkg/hadolint/mocks/hadolintPiperFileUtils.go diff --git a/.mockery.yaml b/.mockery.yml similarity index 51% rename from .mockery.yaml rename to .mockery.yml index aa8812cd9b..2f61192c52 100644 --- a/.mockery.yaml +++ b/.mockery.yml @@ -1,8 +1,28 @@ -quiet: false mockname: "{{.InterfaceName}}" filename: "{{.InterfaceName}}.go" +dir: "{{.InterfaceDir}}/mocks" outpkg: mocks +quiet: false packages: + github.com/SAP/jenkins-library/cmd: + interfaces: + GithubRepoClient: + HadolintPiperFileUtils: + HadolintClient: + github.com/SAP/jenkins-library/pkg/config: + interfaces: + VaultClient: + github.com/SAP/jenkins-library/pkg/jenkins: + interfaces: + Artifact: + Build: + CredentialsManager: + Jenkins: + Job: + Task: + github.com/SAP/jenkins-library/pkg/kubernetes: + interfaces: + HelmExecutor: github.com/influxdata/influxdb-client-go/v2: config: dir: pkg/influx/mocks @@ -13,8 +33,3 @@ packages: dir: pkg/influx/mocks interfaces: WriteAPIBlocking: - github.com/SAP/jenkins-library/pkg/config: - config: - dir: pkg/config/mocks - interfaces: - VaultClient: diff --git a/cmd/githubPublishRelease.go b/cmd/githubPublishRelease.go index 8f14adc03d..2267b841cb 100644 --- a/cmd/githubPublishRelease.go +++ b/cmd/githubPublishRelease.go @@ -16,7 +16,6 @@ import ( piperGithub "github.com/SAP/jenkins-library/pkg/github" ) -// mock generated with: mockery --name GithubRepoClient --dir cmd --output cmd/mocks type GithubRepoClient interface { CreateRelease(ctx context.Context, owner string, repo string, release *github.RepositoryRelease) (*github.RepositoryRelease, *github.Response, error) DeleteReleaseAsset(ctx context.Context, owner string, repo string, id int64) (*github.Response, error) diff --git a/cmd/hadolintExecute.go b/cmd/hadolintExecute.go index 6eb66bcdee..fcfcf4f3a0 100644 --- a/cmd/hadolintExecute.go +++ b/cmd/hadolintExecute.go @@ -18,7 +18,6 @@ import ( const hadolintCommand = "hadolint" // HadolintPiperFileUtils abstracts piperutils.Files -// mock generated with: mockery --name HadolintPiperFileUtils --dir cmd --output pkg/hadolint/mocks type HadolintPiperFileUtils interface { FileExists(filename string) (bool, error) FileWrite(filename string, data []byte, perm os.FileMode) error @@ -26,7 +25,6 @@ type HadolintPiperFileUtils interface { } // HadolintClient abstracts http.Client -// mock generated with: mockery --name hadolintClient --dir cmd --output pkg/hadolint/mocks type HadolintClient interface { SetOptions(options piperhttp.ClientOptions) DownloadFile(url, filename string, header http.Header, cookies []*http.Cookie) error diff --git a/cmd/hadolintExecute_test.go b/cmd/hadolintExecute_test.go index f1c1c0921d..11422c157d 100644 --- a/cmd/hadolintExecute_test.go +++ b/cmd/hadolintExecute_test.go @@ -6,7 +6,7 @@ package cmd import ( "testing" - "github.com/SAP/jenkins-library/pkg/hadolint/mocks" + "github.com/SAP/jenkins-library/cmd/mocks" piperMocks "github.com/SAP/jenkins-library/pkg/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/cmd/mocks/GithubRepoClient.go b/cmd/mocks/GithubRepoClient.go index 625ed61c9f..3c8394915a 100644 --- a/cmd/mocks/GithubRepoClient.go +++ b/cmd/mocks/GithubRepoClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.4. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks @@ -16,11 +16,28 @@ type GithubRepoClient struct { mock.Mock } +type GithubRepoClient_Expecter struct { + mock *mock.Mock +} + +func (_m *GithubRepoClient) EXPECT() *GithubRepoClient_Expecter { + return &GithubRepoClient_Expecter{mock: &_m.Mock} +} + // CreateRelease provides a mock function with given fields: ctx, owner, repo, release func (_m *GithubRepoClient) CreateRelease(ctx context.Context, owner string, repo string, release *github.RepositoryRelease) (*github.RepositoryRelease, *github.Response, error) { ret := _m.Called(ctx, owner, repo, release) + if len(ret) == 0 { + panic("no return value specified for CreateRelease") + } + var r0 *github.RepositoryRelease + var r1 *github.Response + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, *github.RepositoryRelease) (*github.RepositoryRelease, *github.Response, error)); ok { + return rf(ctx, owner, repo, release) + } if rf, ok := ret.Get(0).(func(context.Context, string, string, *github.RepositoryRelease) *github.RepositoryRelease); ok { r0 = rf(ctx, owner, repo, release) } else { @@ -29,7 +46,6 @@ func (_m *GithubRepoClient) CreateRelease(ctx context.Context, owner string, rep } } - var r1 *github.Response if rf, ok := ret.Get(1).(func(context.Context, string, string, *github.RepositoryRelease) *github.Response); ok { r1 = rf(ctx, owner, repo, release) } else { @@ -38,7 +54,6 @@ func (_m *GithubRepoClient) CreateRelease(ctx context.Context, owner string, rep } } - var r2 error if rf, ok := ret.Get(2).(func(context.Context, string, string, *github.RepositoryRelease) error); ok { r2 = rf(ctx, owner, repo, release) } else { @@ -48,11 +63,50 @@ func (_m *GithubRepoClient) CreateRelease(ctx context.Context, owner string, rep return r0, r1, r2 } +// GithubRepoClient_CreateRelease_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRelease' +type GithubRepoClient_CreateRelease_Call struct { + *mock.Call +} + +// CreateRelease is a helper method to define mock.On call +// - ctx context.Context +// - owner string +// - repo string +// - release *github.RepositoryRelease +func (_e *GithubRepoClient_Expecter) CreateRelease(ctx interface{}, owner interface{}, repo interface{}, release interface{}) *GithubRepoClient_CreateRelease_Call { + return &GithubRepoClient_CreateRelease_Call{Call: _e.mock.On("CreateRelease", ctx, owner, repo, release)} +} + +func (_c *GithubRepoClient_CreateRelease_Call) Run(run func(ctx context.Context, owner string, repo string, release *github.RepositoryRelease)) *GithubRepoClient_CreateRelease_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(*github.RepositoryRelease)) + }) + return _c +} + +func (_c *GithubRepoClient_CreateRelease_Call) Return(_a0 *github.RepositoryRelease, _a1 *github.Response, _a2 error) *GithubRepoClient_CreateRelease_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *GithubRepoClient_CreateRelease_Call) RunAndReturn(run func(context.Context, string, string, *github.RepositoryRelease) (*github.RepositoryRelease, *github.Response, error)) *GithubRepoClient_CreateRelease_Call { + _c.Call.Return(run) + return _c +} + // DeleteReleaseAsset provides a mock function with given fields: ctx, owner, repo, id func (_m *GithubRepoClient) DeleteReleaseAsset(ctx context.Context, owner string, repo string, id int64) (*github.Response, error) { ret := _m.Called(ctx, owner, repo, id) + if len(ret) == 0 { + panic("no return value specified for DeleteReleaseAsset") + } + var r0 *github.Response + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, int64) (*github.Response, error)); ok { + return rf(ctx, owner, repo, id) + } if rf, ok := ret.Get(0).(func(context.Context, string, string, int64) *github.Response); ok { r0 = rf(ctx, owner, repo, id) } else { @@ -61,7 +115,6 @@ func (_m *GithubRepoClient) DeleteReleaseAsset(ctx context.Context, owner string } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, string, int64) error); ok { r1 = rf(ctx, owner, repo, id) } else { @@ -71,11 +124,51 @@ func (_m *GithubRepoClient) DeleteReleaseAsset(ctx context.Context, owner string return r0, r1 } +// GithubRepoClient_DeleteReleaseAsset_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteReleaseAsset' +type GithubRepoClient_DeleteReleaseAsset_Call struct { + *mock.Call +} + +// DeleteReleaseAsset is a helper method to define mock.On call +// - ctx context.Context +// - owner string +// - repo string +// - id int64 +func (_e *GithubRepoClient_Expecter) DeleteReleaseAsset(ctx interface{}, owner interface{}, repo interface{}, id interface{}) *GithubRepoClient_DeleteReleaseAsset_Call { + return &GithubRepoClient_DeleteReleaseAsset_Call{Call: _e.mock.On("DeleteReleaseAsset", ctx, owner, repo, id)} +} + +func (_c *GithubRepoClient_DeleteReleaseAsset_Call) Run(run func(ctx context.Context, owner string, repo string, id int64)) *GithubRepoClient_DeleteReleaseAsset_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(int64)) + }) + return _c +} + +func (_c *GithubRepoClient_DeleteReleaseAsset_Call) Return(_a0 *github.Response, _a1 error) *GithubRepoClient_DeleteReleaseAsset_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *GithubRepoClient_DeleteReleaseAsset_Call) RunAndReturn(run func(context.Context, string, string, int64) (*github.Response, error)) *GithubRepoClient_DeleteReleaseAsset_Call { + _c.Call.Return(run) + return _c +} + // GetLatestRelease provides a mock function with given fields: ctx, owner, repo func (_m *GithubRepoClient) GetLatestRelease(ctx context.Context, owner string, repo string) (*github.RepositoryRelease, *github.Response, error) { ret := _m.Called(ctx, owner, repo) + if len(ret) == 0 { + panic("no return value specified for GetLatestRelease") + } + var r0 *github.RepositoryRelease + var r1 *github.Response + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*github.RepositoryRelease, *github.Response, error)); ok { + return rf(ctx, owner, repo) + } if rf, ok := ret.Get(0).(func(context.Context, string, string) *github.RepositoryRelease); ok { r0 = rf(ctx, owner, repo) } else { @@ -84,7 +177,6 @@ func (_m *GithubRepoClient) GetLatestRelease(ctx context.Context, owner string, } } - var r1 *github.Response if rf, ok := ret.Get(1).(func(context.Context, string, string) *github.Response); ok { r1 = rf(ctx, owner, repo) } else { @@ -93,7 +185,6 @@ func (_m *GithubRepoClient) GetLatestRelease(ctx context.Context, owner string, } } - var r2 error if rf, ok := ret.Get(2).(func(context.Context, string, string) error); ok { r2 = rf(ctx, owner, repo) } else { @@ -103,11 +194,50 @@ func (_m *GithubRepoClient) GetLatestRelease(ctx context.Context, owner string, return r0, r1, r2 } +// GithubRepoClient_GetLatestRelease_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLatestRelease' +type GithubRepoClient_GetLatestRelease_Call struct { + *mock.Call +} + +// GetLatestRelease is a helper method to define mock.On call +// - ctx context.Context +// - owner string +// - repo string +func (_e *GithubRepoClient_Expecter) GetLatestRelease(ctx interface{}, owner interface{}, repo interface{}) *GithubRepoClient_GetLatestRelease_Call { + return &GithubRepoClient_GetLatestRelease_Call{Call: _e.mock.On("GetLatestRelease", ctx, owner, repo)} +} + +func (_c *GithubRepoClient_GetLatestRelease_Call) Run(run func(ctx context.Context, owner string, repo string)) *GithubRepoClient_GetLatestRelease_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *GithubRepoClient_GetLatestRelease_Call) Return(_a0 *github.RepositoryRelease, _a1 *github.Response, _a2 error) *GithubRepoClient_GetLatestRelease_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *GithubRepoClient_GetLatestRelease_Call) RunAndReturn(run func(context.Context, string, string) (*github.RepositoryRelease, *github.Response, error)) *GithubRepoClient_GetLatestRelease_Call { + _c.Call.Return(run) + return _c +} + // ListReleaseAssets provides a mock function with given fields: ctx, owner, repo, id, opt func (_m *GithubRepoClient) ListReleaseAssets(ctx context.Context, owner string, repo string, id int64, opt *github.ListOptions) ([]*github.ReleaseAsset, *github.Response, error) { ret := _m.Called(ctx, owner, repo, id, opt) + if len(ret) == 0 { + panic("no return value specified for ListReleaseAssets") + } + var r0 []*github.ReleaseAsset + var r1 *github.Response + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, int64, *github.ListOptions) ([]*github.ReleaseAsset, *github.Response, error)); ok { + return rf(ctx, owner, repo, id, opt) + } if rf, ok := ret.Get(0).(func(context.Context, string, string, int64, *github.ListOptions) []*github.ReleaseAsset); ok { r0 = rf(ctx, owner, repo, id, opt) } else { @@ -116,7 +246,6 @@ func (_m *GithubRepoClient) ListReleaseAssets(ctx context.Context, owner string, } } - var r1 *github.Response if rf, ok := ret.Get(1).(func(context.Context, string, string, int64, *github.ListOptions) *github.Response); ok { r1 = rf(ctx, owner, repo, id, opt) } else { @@ -125,7 +254,6 @@ func (_m *GithubRepoClient) ListReleaseAssets(ctx context.Context, owner string, } } - var r2 error if rf, ok := ret.Get(2).(func(context.Context, string, string, int64, *github.ListOptions) error); ok { r2 = rf(ctx, owner, repo, id, opt) } else { @@ -135,11 +263,52 @@ func (_m *GithubRepoClient) ListReleaseAssets(ctx context.Context, owner string, return r0, r1, r2 } +// GithubRepoClient_ListReleaseAssets_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListReleaseAssets' +type GithubRepoClient_ListReleaseAssets_Call struct { + *mock.Call +} + +// ListReleaseAssets is a helper method to define mock.On call +// - ctx context.Context +// - owner string +// - repo string +// - id int64 +// - opt *github.ListOptions +func (_e *GithubRepoClient_Expecter) ListReleaseAssets(ctx interface{}, owner interface{}, repo interface{}, id interface{}, opt interface{}) *GithubRepoClient_ListReleaseAssets_Call { + return &GithubRepoClient_ListReleaseAssets_Call{Call: _e.mock.On("ListReleaseAssets", ctx, owner, repo, id, opt)} +} + +func (_c *GithubRepoClient_ListReleaseAssets_Call) Run(run func(ctx context.Context, owner string, repo string, id int64, opt *github.ListOptions)) *GithubRepoClient_ListReleaseAssets_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(int64), args[4].(*github.ListOptions)) + }) + return _c +} + +func (_c *GithubRepoClient_ListReleaseAssets_Call) Return(_a0 []*github.ReleaseAsset, _a1 *github.Response, _a2 error) *GithubRepoClient_ListReleaseAssets_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *GithubRepoClient_ListReleaseAssets_Call) RunAndReturn(run func(context.Context, string, string, int64, *github.ListOptions) ([]*github.ReleaseAsset, *github.Response, error)) *GithubRepoClient_ListReleaseAssets_Call { + _c.Call.Return(run) + return _c +} + // UploadReleaseAsset provides a mock function with given fields: ctx, owner, repo, id, opt, file func (_m *GithubRepoClient) UploadReleaseAsset(ctx context.Context, owner string, repo string, id int64, opt *github.UploadOptions, file *os.File) (*github.ReleaseAsset, *github.Response, error) { ret := _m.Called(ctx, owner, repo, id, opt, file) + if len(ret) == 0 { + panic("no return value specified for UploadReleaseAsset") + } + var r0 *github.ReleaseAsset + var r1 *github.Response + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, int64, *github.UploadOptions, *os.File) (*github.ReleaseAsset, *github.Response, error)); ok { + return rf(ctx, owner, repo, id, opt, file) + } if rf, ok := ret.Get(0).(func(context.Context, string, string, int64, *github.UploadOptions, *os.File) *github.ReleaseAsset); ok { r0 = rf(ctx, owner, repo, id, opt, file) } else { @@ -148,7 +317,6 @@ func (_m *GithubRepoClient) UploadReleaseAsset(ctx context.Context, owner string } } - var r1 *github.Response if rf, ok := ret.Get(1).(func(context.Context, string, string, int64, *github.UploadOptions, *os.File) *github.Response); ok { r1 = rf(ctx, owner, repo, id, opt, file) } else { @@ -157,7 +325,6 @@ func (_m *GithubRepoClient) UploadReleaseAsset(ctx context.Context, owner string } } - var r2 error if rf, ok := ret.Get(2).(func(context.Context, string, string, int64, *github.UploadOptions, *os.File) error); ok { r2 = rf(ctx, owner, repo, id, opt, file) } else { @@ -166,3 +333,50 @@ func (_m *GithubRepoClient) UploadReleaseAsset(ctx context.Context, owner string return r0, r1, r2 } + +// GithubRepoClient_UploadReleaseAsset_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UploadReleaseAsset' +type GithubRepoClient_UploadReleaseAsset_Call struct { + *mock.Call +} + +// UploadReleaseAsset is a helper method to define mock.On call +// - ctx context.Context +// - owner string +// - repo string +// - id int64 +// - opt *github.UploadOptions +// - file *os.File +func (_e *GithubRepoClient_Expecter) UploadReleaseAsset(ctx interface{}, owner interface{}, repo interface{}, id interface{}, opt interface{}, file interface{}) *GithubRepoClient_UploadReleaseAsset_Call { + return &GithubRepoClient_UploadReleaseAsset_Call{Call: _e.mock.On("UploadReleaseAsset", ctx, owner, repo, id, opt, file)} +} + +func (_c *GithubRepoClient_UploadReleaseAsset_Call) Run(run func(ctx context.Context, owner string, repo string, id int64, opt *github.UploadOptions, file *os.File)) *GithubRepoClient_UploadReleaseAsset_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(int64), args[4].(*github.UploadOptions), args[5].(*os.File)) + }) + return _c +} + +func (_c *GithubRepoClient_UploadReleaseAsset_Call) Return(_a0 *github.ReleaseAsset, _a1 *github.Response, _a2 error) *GithubRepoClient_UploadReleaseAsset_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *GithubRepoClient_UploadReleaseAsset_Call) RunAndReturn(run func(context.Context, string, string, int64, *github.UploadOptions, *os.File) (*github.ReleaseAsset, *github.Response, error)) *GithubRepoClient_UploadReleaseAsset_Call { + _c.Call.Return(run) + return _c +} + +// NewGithubRepoClient creates a new instance of GithubRepoClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewGithubRepoClient(t interface { + mock.TestingT + Cleanup(func()) +}) *GithubRepoClient { + mock := &GithubRepoClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/cmd/mocks/hadolintClient.go b/cmd/mocks/hadolintClient.go new file mode 100644 index 0000000000..4c8eb7131b --- /dev/null +++ b/cmd/mocks/hadolintClient.go @@ -0,0 +1,119 @@ +// Code generated by mockery v2.43.0. DO NOT EDIT. + +package mocks + +import ( + http "net/http" + + pkghttp "github.com/SAP/jenkins-library/pkg/http" + mock "github.com/stretchr/testify/mock" +) + +// HadolintClient is an autogenerated mock type for the HadolintClient type +type HadolintClient struct { + mock.Mock +} + +type HadolintClient_Expecter struct { + mock *mock.Mock +} + +func (_m *HadolintClient) EXPECT() *HadolintClient_Expecter { + return &HadolintClient_Expecter{mock: &_m.Mock} +} + +// DownloadFile provides a mock function with given fields: url, filename, header, cookies +func (_m *HadolintClient) DownloadFile(url string, filename string, header http.Header, cookies []*http.Cookie) error { + ret := _m.Called(url, filename, header, cookies) + + if len(ret) == 0 { + panic("no return value specified for DownloadFile") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, string, http.Header, []*http.Cookie) error); ok { + r0 = rf(url, filename, header, cookies) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// HadolintClient_DownloadFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DownloadFile' +type HadolintClient_DownloadFile_Call struct { + *mock.Call +} + +// DownloadFile is a helper method to define mock.On call +// - url string +// - filename string +// - header http.Header +// - cookies []*http.Cookie +func (_e *HadolintClient_Expecter) DownloadFile(url interface{}, filename interface{}, header interface{}, cookies interface{}) *HadolintClient_DownloadFile_Call { + return &HadolintClient_DownloadFile_Call{Call: _e.mock.On("DownloadFile", url, filename, header, cookies)} +} + +func (_c *HadolintClient_DownloadFile_Call) Run(run func(url string, filename string, header http.Header, cookies []*http.Cookie)) *HadolintClient_DownloadFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string), args[2].(http.Header), args[3].([]*http.Cookie)) + }) + return _c +} + +func (_c *HadolintClient_DownloadFile_Call) Return(_a0 error) *HadolintClient_DownloadFile_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HadolintClient_DownloadFile_Call) RunAndReturn(run func(string, string, http.Header, []*http.Cookie) error) *HadolintClient_DownloadFile_Call { + _c.Call.Return(run) + return _c +} + +// SetOptions provides a mock function with given fields: options +func (_m *HadolintClient) SetOptions(options pkghttp.ClientOptions) { + _m.Called(options) +} + +// HadolintClient_SetOptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetOptions' +type HadolintClient_SetOptions_Call struct { + *mock.Call +} + +// SetOptions is a helper method to define mock.On call +// - options pkghttp.ClientOptions +func (_e *HadolintClient_Expecter) SetOptions(options interface{}) *HadolintClient_SetOptions_Call { + return &HadolintClient_SetOptions_Call{Call: _e.mock.On("SetOptions", options)} +} + +func (_c *HadolintClient_SetOptions_Call) Run(run func(options pkghttp.ClientOptions)) *HadolintClient_SetOptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(pkghttp.ClientOptions)) + }) + return _c +} + +func (_c *HadolintClient_SetOptions_Call) Return() *HadolintClient_SetOptions_Call { + _c.Call.Return() + return _c +} + +func (_c *HadolintClient_SetOptions_Call) RunAndReturn(run func(pkghttp.ClientOptions)) *HadolintClient_SetOptions_Call { + _c.Call.Return(run) + return _c +} + +// NewHadolintClient creates a new instance of HadolintClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewHadolintClient(t interface { + mock.TestingT + Cleanup(func()) +}) *HadolintClient { + mock := &HadolintClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/cmd/mocks/hadolintPiperFileUtils.go b/cmd/mocks/hadolintPiperFileUtils.go new file mode 100644 index 0000000000..5ef9b46edb --- /dev/null +++ b/cmd/mocks/hadolintPiperFileUtils.go @@ -0,0 +1,188 @@ +// Code generated by mockery v2.43.0. DO NOT EDIT. + +package mocks + +import ( + fs "io/fs" + + mock "github.com/stretchr/testify/mock" +) + +// HadolintPiperFileUtils is an autogenerated mock type for the HadolintPiperFileUtils type +type HadolintPiperFileUtils struct { + mock.Mock +} + +type HadolintPiperFileUtils_Expecter struct { + mock *mock.Mock +} + +func (_m *HadolintPiperFileUtils) EXPECT() *HadolintPiperFileUtils_Expecter { + return &HadolintPiperFileUtils_Expecter{mock: &_m.Mock} +} + +// FileExists provides a mock function with given fields: filename +func (_m *HadolintPiperFileUtils) FileExists(filename string) (bool, error) { + ret := _m.Called(filename) + + if len(ret) == 0 { + panic("no return value specified for FileExists") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(string) (bool, error)); ok { + return rf(filename) + } + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(filename) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(filename) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// HadolintPiperFileUtils_FileExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FileExists' +type HadolintPiperFileUtils_FileExists_Call struct { + *mock.Call +} + +// FileExists is a helper method to define mock.On call +// - filename string +func (_e *HadolintPiperFileUtils_Expecter) FileExists(filename interface{}) *HadolintPiperFileUtils_FileExists_Call { + return &HadolintPiperFileUtils_FileExists_Call{Call: _e.mock.On("FileExists", filename)} +} + +func (_c *HadolintPiperFileUtils_FileExists_Call) Run(run func(filename string)) *HadolintPiperFileUtils_FileExists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *HadolintPiperFileUtils_FileExists_Call) Return(_a0 bool, _a1 error) *HadolintPiperFileUtils_FileExists_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *HadolintPiperFileUtils_FileExists_Call) RunAndReturn(run func(string) (bool, error)) *HadolintPiperFileUtils_FileExists_Call { + _c.Call.Return(run) + return _c +} + +// FileWrite provides a mock function with given fields: filename, data, perm +func (_m *HadolintPiperFileUtils) FileWrite(filename string, data []byte, perm fs.FileMode) error { + ret := _m.Called(filename, data, perm) + + if len(ret) == 0 { + panic("no return value specified for FileWrite") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, []byte, fs.FileMode) error); ok { + r0 = rf(filename, data, perm) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// HadolintPiperFileUtils_FileWrite_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FileWrite' +type HadolintPiperFileUtils_FileWrite_Call struct { + *mock.Call +} + +// FileWrite is a helper method to define mock.On call +// - filename string +// - data []byte +// - perm fs.FileMode +func (_e *HadolintPiperFileUtils_Expecter) FileWrite(filename interface{}, data interface{}, perm interface{}) *HadolintPiperFileUtils_FileWrite_Call { + return &HadolintPiperFileUtils_FileWrite_Call{Call: _e.mock.On("FileWrite", filename, data, perm)} +} + +func (_c *HadolintPiperFileUtils_FileWrite_Call) Run(run func(filename string, data []byte, perm fs.FileMode)) *HadolintPiperFileUtils_FileWrite_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].([]byte), args[2].(fs.FileMode)) + }) + return _c +} + +func (_c *HadolintPiperFileUtils_FileWrite_Call) Return(_a0 error) *HadolintPiperFileUtils_FileWrite_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HadolintPiperFileUtils_FileWrite_Call) RunAndReturn(run func(string, []byte, fs.FileMode) error) *HadolintPiperFileUtils_FileWrite_Call { + _c.Call.Return(run) + return _c +} + +// WriteFile provides a mock function with given fields: filename, data, perm +func (_m *HadolintPiperFileUtils) WriteFile(filename string, data []byte, perm fs.FileMode) error { + ret := _m.Called(filename, data, perm) + + if len(ret) == 0 { + panic("no return value specified for WriteFile") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, []byte, fs.FileMode) error); ok { + r0 = rf(filename, data, perm) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// HadolintPiperFileUtils_WriteFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteFile' +type HadolintPiperFileUtils_WriteFile_Call struct { + *mock.Call +} + +// WriteFile is a helper method to define mock.On call +// - filename string +// - data []byte +// - perm fs.FileMode +func (_e *HadolintPiperFileUtils_Expecter) WriteFile(filename interface{}, data interface{}, perm interface{}) *HadolintPiperFileUtils_WriteFile_Call { + return &HadolintPiperFileUtils_WriteFile_Call{Call: _e.mock.On("WriteFile", filename, data, perm)} +} + +func (_c *HadolintPiperFileUtils_WriteFile_Call) Run(run func(filename string, data []byte, perm fs.FileMode)) *HadolintPiperFileUtils_WriteFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].([]byte), args[2].(fs.FileMode)) + }) + return _c +} + +func (_c *HadolintPiperFileUtils_WriteFile_Call) Return(_a0 error) *HadolintPiperFileUtils_WriteFile_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HadolintPiperFileUtils_WriteFile_Call) RunAndReturn(run func(string, []byte, fs.FileMode) error) *HadolintPiperFileUtils_WriteFile_Call { + _c.Call.Return(run) + return _c +} + +// NewHadolintPiperFileUtils creates a new instance of HadolintPiperFileUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewHadolintPiperFileUtils(t interface { + mock.TestingT + Cleanup(func()) +}) *HadolintPiperFileUtils { + mock := &HadolintPiperFileUtils{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/config/mocks/vaultClient.go b/pkg/config/mocks/vaultClient.go index 3b6b8f9adb..ad6b788578 100644 --- a/pkg/config/mocks/vaultClient.go +++ b/pkg/config/mocks/vaultClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks diff --git a/pkg/hadolint/mocks/hadolintClient.go b/pkg/hadolint/mocks/hadolintClient.go deleted file mode 100644 index 465d062a50..0000000000 --- a/pkg/hadolint/mocks/hadolintClient.go +++ /dev/null @@ -1,34 +0,0 @@ -// Code generated by mockery v2.0.0-alpha.13. DO NOT EDIT. - -package mocks - -import ( - http "net/http" - - pkghttp "github.com/SAP/jenkins-library/pkg/http" - mock "github.com/stretchr/testify/mock" -) - -// HadolintClient is an autogenerated mock type for the HadolintClient type -type HadolintClient struct { - mock.Mock -} - -// DownloadFile provides a mock function with given fields: url, filename, header, cookies -func (_m *HadolintClient) DownloadFile(url string, filename string, header http.Header, cookies []*http.Cookie) error { - ret := _m.Called(url, filename, header, cookies) - - var r0 error - if rf, ok := ret.Get(0).(func(string, string, http.Header, []*http.Cookie) error); ok { - r0 = rf(url, filename, header, cookies) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SetOptions provides a mock function with given fields: options -func (_m *HadolintClient) SetOptions(options pkghttp.ClientOptions) { - _m.Called(options) -} diff --git a/pkg/hadolint/mocks/hadolintPiperFileUtils.go b/pkg/hadolint/mocks/hadolintPiperFileUtils.go deleted file mode 100644 index a16993e8ca..0000000000 --- a/pkg/hadolint/mocks/hadolintPiperFileUtils.go +++ /dev/null @@ -1,62 +0,0 @@ -// Code generated by mockery v2.0.0-alpha.13. DO NOT EDIT. - -package mocks - -import ( - os "os" - - mock "github.com/stretchr/testify/mock" -) - -// HadolintPiperFileUtils is an autogenerated mock type for the HadolintPiperFileUtils type -type HadolintPiperFileUtils struct { - mock.Mock -} - -// FileExists provides a mock function with given fields: filename -func (_m *HadolintPiperFileUtils) FileExists(filename string) (bool, error) { - ret := _m.Called(filename) - - var r0 bool - if rf, ok := ret.Get(0).(func(string) bool); ok { - r0 = rf(filename) - } else { - r0 = ret.Get(0).(bool) - } - - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(filename) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// FileWrite provides a mock function with given fields: filename, data, perm -func (_m *HadolintPiperFileUtils) FileWrite(filename string, data []byte, perm os.FileMode) error { - ret := _m.Called(filename, data, perm) - - var r0 error - if rf, ok := ret.Get(0).(func(string, []byte, os.FileMode) error); ok { - r0 = rf(filename, data, perm) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -func (_m *HadolintPiperFileUtils) WriteFile(filename string, data []byte, perm os.FileMode) error { - ret := _m.Called(filename, data, perm) - - var r0 error - if rf, ok := ret.Get(0).(func(string, []byte, os.FileMode) error); ok { - r0 = rf(filename, data, perm) - } else { - r0 = ret.Error(0) - } - - return r0 -} diff --git a/pkg/influx/mocks/Client.go b/pkg/influx/mocks/Client.go index ad616fdefd..491d0f59a1 100644 --- a/pkg/influx/mocks/Client.go +++ b/pkg/influx/mocks/Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks diff --git a/pkg/influx/mocks/WriteAPIBlocking.go b/pkg/influx/mocks/WriteAPIBlocking.go index bf2549831f..4e898bef17 100644 --- a/pkg/influx/mocks/WriteAPIBlocking.go +++ b/pkg/influx/mocks/WriteAPIBlocking.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks diff --git a/pkg/jenkins/artifact.go b/pkg/jenkins/artifact.go index 478b1e0b0f..6097e9bdf0 100644 --- a/pkg/jenkins/artifact.go +++ b/pkg/jenkins/artifact.go @@ -7,7 +7,6 @@ import ( ) // Artifact is an interface to abstract gojenkins.Artifact. -// mock generated with: mockery --name Artifact --dir pkg/jenkins --output pkg/jenkins/mocks type Artifact interface { Save(ctx context.Context, path string) (bool, error) SaveToDir(ctx context.Context, dir string) (bool, error) diff --git a/pkg/jenkins/build.go b/pkg/jenkins/build.go index 4f693fa4a0..e1278e1ea4 100644 --- a/pkg/jenkins/build.go +++ b/pkg/jenkins/build.go @@ -10,7 +10,6 @@ import ( ) // Build is an interface to abstract gojenkins.Build. -// mock generated with: mockery --name Build --dir pkg/jenkins --output pkg/jenkins/mocks type Build interface { GetArtifacts() []gojenkins.Artifact IsRunning(ctx context.Context) bool diff --git a/pkg/jenkins/credential.go b/pkg/jenkins/credential.go index eb3f6af2ef..4495f727c4 100644 --- a/pkg/jenkins/credential.go +++ b/pkg/jenkins/credential.go @@ -22,7 +22,6 @@ type SSHCredentials = gojenkins.SSHCredentials type DockerServerCredentials = gojenkins.DockerServerCredentials // CredentialsManager is utility to control credential plugin -// mock generated with: mockery --name CredentialsManager --dir pkg/jenkins --output pkg/jenkins/mocks type CredentialsManager interface { Update(context.Context, string, string, interface{}) error } diff --git a/pkg/jenkins/jenkins.go b/pkg/jenkins/jenkins.go index 4cf9c92510..a654fef918 100644 --- a/pkg/jenkins/jenkins.go +++ b/pkg/jenkins/jenkins.go @@ -11,7 +11,6 @@ import ( ) // Jenkins is an interface to abstract gojenkins.Jenkins. -// mock generated with: mockery --name Jenkins --dir pkg/jenkins --output pkg/jenkins/mocks type Jenkins interface { GetJobObj(ctx context.Context, name string) *gojenkins.Job BuildJob(ctx context.Context, name string, params map[string]string) (int64, error) diff --git a/pkg/jenkins/job.go b/pkg/jenkins/job.go index 721aa9e01e..a379a63ba6 100644 --- a/pkg/jenkins/job.go +++ b/pkg/jenkins/job.go @@ -7,7 +7,6 @@ import ( ) // Task is an interface to abstract gojenkins.Task. -// mock generated with: mockery --name Job --dir pkg/jenkins --output pkg/jenkins/mocks type Job interface { Poll(context.Context) (int, error) InvokeSimple(ctx context.Context, params map[string]string) (int64, error) diff --git a/pkg/jenkins/mocks/Artifact.go b/pkg/jenkins/mocks/Artifact.go index 74598f017a..629dcc6897 100644 --- a/pkg/jenkins/mocks/Artifact.go +++ b/pkg/jenkins/mocks/Artifact.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.7.5. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks @@ -13,10 +13,22 @@ type Artifact struct { mock.Mock } +type Artifact_Expecter struct { + mock *mock.Mock +} + +func (_m *Artifact) EXPECT() *Artifact_Expecter { + return &Artifact_Expecter{mock: &_m.Mock} +} + // FileName provides a mock function with given fields: func (_m *Artifact) FileName() string { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FileName") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() @@ -27,11 +39,46 @@ func (_m *Artifact) FileName() string { return r0 } +// Artifact_FileName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FileName' +type Artifact_FileName_Call struct { + *mock.Call +} + +// FileName is a helper method to define mock.On call +func (_e *Artifact_Expecter) FileName() *Artifact_FileName_Call { + return &Artifact_FileName_Call{Call: _e.mock.On("FileName")} +} + +func (_c *Artifact_FileName_Call) Run(run func()) *Artifact_FileName_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Artifact_FileName_Call) Return(_a0 string) *Artifact_FileName_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Artifact_FileName_Call) RunAndReturn(run func() string) *Artifact_FileName_Call { + _c.Call.Return(run) + return _c +} + // GetData provides a mock function with given fields: ctx func (_m *Artifact) GetData(ctx context.Context) ([]byte, error) { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for GetData") + } + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]byte, error)); ok { + return rf(ctx) + } if rf, ok := ret.Get(0).(func(context.Context) []byte); ok { r0 = rf(ctx) } else { @@ -40,7 +87,6 @@ func (_m *Artifact) GetData(ctx context.Context) ([]byte, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context) error); ok { r1 = rf(ctx) } else { @@ -50,18 +96,53 @@ func (_m *Artifact) GetData(ctx context.Context) ([]byte, error) { return r0, r1 } +// Artifact_GetData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetData' +type Artifact_GetData_Call struct { + *mock.Call +} + +// GetData is a helper method to define mock.On call +// - ctx context.Context +func (_e *Artifact_Expecter) GetData(ctx interface{}) *Artifact_GetData_Call { + return &Artifact_GetData_Call{Call: _e.mock.On("GetData", ctx)} +} + +func (_c *Artifact_GetData_Call) Run(run func(ctx context.Context)) *Artifact_GetData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *Artifact_GetData_Call) Return(_a0 []byte, _a1 error) *Artifact_GetData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Artifact_GetData_Call) RunAndReturn(run func(context.Context) ([]byte, error)) *Artifact_GetData_Call { + _c.Call.Return(run) + return _c +} + // Save provides a mock function with given fields: ctx, path func (_m *Artifact) Save(ctx context.Context, path string) (bool, error) { ret := _m.Called(ctx, path) + if len(ret) == 0 { + panic("no return value specified for Save") + } + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (bool, error)); ok { + return rf(ctx, path) + } if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok { r0 = rf(ctx, path) } else { r0 = ret.Get(0).(bool) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { r1 = rf(ctx, path) } else { @@ -71,18 +152,54 @@ func (_m *Artifact) Save(ctx context.Context, path string) (bool, error) { return r0, r1 } +// Artifact_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' +type Artifact_Save_Call struct { + *mock.Call +} + +// Save is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *Artifact_Expecter) Save(ctx interface{}, path interface{}) *Artifact_Save_Call { + return &Artifact_Save_Call{Call: _e.mock.On("Save", ctx, path)} +} + +func (_c *Artifact_Save_Call) Run(run func(ctx context.Context, path string)) *Artifact_Save_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Artifact_Save_Call) Return(_a0 bool, _a1 error) *Artifact_Save_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Artifact_Save_Call) RunAndReturn(run func(context.Context, string) (bool, error)) *Artifact_Save_Call { + _c.Call.Return(run) + return _c +} + // SaveToDir provides a mock function with given fields: ctx, dir func (_m *Artifact) SaveToDir(ctx context.Context, dir string) (bool, error) { ret := _m.Called(ctx, dir) + if len(ret) == 0 { + panic("no return value specified for SaveToDir") + } + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (bool, error)); ok { + return rf(ctx, dir) + } if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok { r0 = rf(ctx, dir) } else { r0 = ret.Get(0).(bool) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { r1 = rf(ctx, dir) } else { @@ -91,3 +208,46 @@ func (_m *Artifact) SaveToDir(ctx context.Context, dir string) (bool, error) { return r0, r1 } + +// Artifact_SaveToDir_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveToDir' +type Artifact_SaveToDir_Call struct { + *mock.Call +} + +// SaveToDir is a helper method to define mock.On call +// - ctx context.Context +// - dir string +func (_e *Artifact_Expecter) SaveToDir(ctx interface{}, dir interface{}) *Artifact_SaveToDir_Call { + return &Artifact_SaveToDir_Call{Call: _e.mock.On("SaveToDir", ctx, dir)} +} + +func (_c *Artifact_SaveToDir_Call) Run(run func(ctx context.Context, dir string)) *Artifact_SaveToDir_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Artifact_SaveToDir_Call) Return(_a0 bool, _a1 error) *Artifact_SaveToDir_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Artifact_SaveToDir_Call) RunAndReturn(run func(context.Context, string) (bool, error)) *Artifact_SaveToDir_Call { + _c.Call.Return(run) + return _c +} + +// NewArtifact creates a new instance of Artifact. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewArtifact(t interface { + mock.TestingT + Cleanup(func()) +}) *Artifact { + mock := &Artifact{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/jenkins/mocks/Build.go b/pkg/jenkins/mocks/Build.go index 302bbeaf70..03c8731c4b 100644 --- a/pkg/jenkins/mocks/Build.go +++ b/pkg/jenkins/mocks/Build.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.7.5. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks @@ -15,10 +15,22 @@ type Build struct { mock.Mock } +type Build_Expecter struct { + mock *mock.Mock +} + +func (_m *Build) EXPECT() *Build_Expecter { + return &Build_Expecter{mock: &_m.Mock} +} + // GetArtifacts provides a mock function with given fields: func (_m *Build) GetArtifacts() []gojenkins.Artifact { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for GetArtifacts") + } + var r0 []gojenkins.Artifact if rf, ok := ret.Get(0).(func() []gojenkins.Artifact); ok { r0 = rf() @@ -31,10 +43,41 @@ func (_m *Build) GetArtifacts() []gojenkins.Artifact { return r0 } +// Build_GetArtifacts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetArtifacts' +type Build_GetArtifacts_Call struct { + *mock.Call +} + +// GetArtifacts is a helper method to define mock.On call +func (_e *Build_Expecter) GetArtifacts() *Build_GetArtifacts_Call { + return &Build_GetArtifacts_Call{Call: _e.mock.On("GetArtifacts")} +} + +func (_c *Build_GetArtifacts_Call) Run(run func()) *Build_GetArtifacts_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Build_GetArtifacts_Call) Return(_a0 []gojenkins.Artifact) *Build_GetArtifacts_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Build_GetArtifacts_Call) RunAndReturn(run func() []gojenkins.Artifact) *Build_GetArtifacts_Call { + _c.Call.Return(run) + return _c +} + // IsRunning provides a mock function with given fields: ctx func (_m *Build) IsRunning(ctx context.Context) bool { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for IsRunning") + } + var r0 bool if rf, ok := ret.Get(0).(func(context.Context) bool); ok { r0 = rf(ctx) @@ -45,6 +88,34 @@ func (_m *Build) IsRunning(ctx context.Context) bool { return r0 } +// Build_IsRunning_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsRunning' +type Build_IsRunning_Call struct { + *mock.Call +} + +// IsRunning is a helper method to define mock.On call +// - ctx context.Context +func (_e *Build_Expecter) IsRunning(ctx interface{}) *Build_IsRunning_Call { + return &Build_IsRunning_Call{Call: _e.mock.On("IsRunning", ctx)} +} + +func (_c *Build_IsRunning_Call) Run(run func(ctx context.Context)) *Build_IsRunning_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *Build_IsRunning_Call) Return(_a0 bool) *Build_IsRunning_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Build_IsRunning_Call) RunAndReturn(run func(context.Context) bool) *Build_IsRunning_Call { + _c.Call.Return(run) + return _c +} + // Poll provides a mock function with given fields: ctx, options func (_m *Build) Poll(ctx context.Context, options ...interface{}) (int, error) { var _ca []interface{} @@ -52,14 +123,21 @@ func (_m *Build) Poll(ctx context.Context, options ...interface{}) (int, error) _ca = append(_ca, options...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Poll") + } + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ...interface{}) (int, error)); ok { + return rf(ctx, options...) + } if rf, ok := ret.Get(0).(func(context.Context, ...interface{}) int); ok { r0 = rf(ctx, options...) } else { r0 = ret.Get(0).(int) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, ...interface{}) error); ok { r1 = rf(ctx, options...) } else { @@ -68,3 +146,53 @@ func (_m *Build) Poll(ctx context.Context, options ...interface{}) (int, error) return r0, r1 } + +// Build_Poll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Poll' +type Build_Poll_Call struct { + *mock.Call +} + +// Poll is a helper method to define mock.On call +// - ctx context.Context +// - options ...interface{} +func (_e *Build_Expecter) Poll(ctx interface{}, options ...interface{}) *Build_Poll_Call { + return &Build_Poll_Call{Call: _e.mock.On("Poll", + append([]interface{}{ctx}, options...)...)} +} + +func (_c *Build_Poll_Call) Run(run func(ctx context.Context, options ...interface{})) *Build_Poll_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), variadicArgs...) + }) + return _c +} + +func (_c *Build_Poll_Call) Return(_a0 int, _a1 error) *Build_Poll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Build_Poll_Call) RunAndReturn(run func(context.Context, ...interface{}) (int, error)) *Build_Poll_Call { + _c.Call.Return(run) + return _c +} + +// NewBuild creates a new instance of Build. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewBuild(t interface { + mock.TestingT + Cleanup(func()) +}) *Build { + mock := &Build{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/jenkins/mocks/CredentialsManager.go b/pkg/jenkins/mocks/CredentialsManager.go index c1bd2b21d6..b4f4392099 100644 --- a/pkg/jenkins/mocks/CredentialsManager.go +++ b/pkg/jenkins/mocks/CredentialsManager.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.7.5. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks @@ -13,10 +13,22 @@ type CredentialsManager struct { mock.Mock } +type CredentialsManager_Expecter struct { + mock *mock.Mock +} + +func (_m *CredentialsManager) EXPECT() *CredentialsManager_Expecter { + return &CredentialsManager_Expecter{mock: &_m.Mock} +} + // Update provides a mock function with given fields: _a0, _a1, _a2, _a3 func (_m *CredentialsManager) Update(_a0 context.Context, _a1 string, _a2 string, _a3 interface{}) error { ret := _m.Called(_a0, _a1, _a2, _a3) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, interface{}) error); ok { r0 = rf(_a0, _a1, _a2, _a3) @@ -26,3 +38,48 @@ func (_m *CredentialsManager) Update(_a0 context.Context, _a1 string, _a2 string return r0 } + +// CredentialsManager_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type CredentialsManager_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 string +// - _a2 string +// - _a3 interface{} +func (_e *CredentialsManager_Expecter) Update(_a0 interface{}, _a1 interface{}, _a2 interface{}, _a3 interface{}) *CredentialsManager_Update_Call { + return &CredentialsManager_Update_Call{Call: _e.mock.On("Update", _a0, _a1, _a2, _a3)} +} + +func (_c *CredentialsManager_Update_Call) Run(run func(_a0 context.Context, _a1 string, _a2 string, _a3 interface{})) *CredentialsManager_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(interface{})) + }) + return _c +} + +func (_c *CredentialsManager_Update_Call) Return(_a0 error) *CredentialsManager_Update_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *CredentialsManager_Update_Call) RunAndReturn(run func(context.Context, string, string, interface{}) error) *CredentialsManager_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewCredentialsManager creates a new instance of CredentialsManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCredentialsManager(t interface { + mock.TestingT + Cleanup(func()) +}) *CredentialsManager { + mock := &CredentialsManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/jenkins/mocks/Jenkins.go b/pkg/jenkins/mocks/Jenkins.go index 2903b97a92..8fb92f5bcc 100644 --- a/pkg/jenkins/mocks/Jenkins.go +++ b/pkg/jenkins/mocks/Jenkins.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.7.5. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks @@ -15,18 +15,33 @@ type Jenkins struct { mock.Mock } +type Jenkins_Expecter struct { + mock *mock.Mock +} + +func (_m *Jenkins) EXPECT() *Jenkins_Expecter { + return &Jenkins_Expecter{mock: &_m.Mock} +} + // BuildJob provides a mock function with given fields: ctx, name, params func (_m *Jenkins) BuildJob(ctx context.Context, name string, params map[string]string) (int64, error) { ret := _m.Called(ctx, name, params) + if len(ret) == 0 { + panic("no return value specified for BuildJob") + } + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, map[string]string) (int64, error)); ok { + return rf(ctx, name, params) + } if rf, ok := ret.Get(0).(func(context.Context, string, map[string]string) int64); ok { r0 = rf(ctx, name, params) } else { r0 = ret.Get(0).(int64) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, map[string]string) error); ok { r1 = rf(ctx, name, params) } else { @@ -36,11 +51,49 @@ func (_m *Jenkins) BuildJob(ctx context.Context, name string, params map[string] return r0, r1 } +// Jenkins_BuildJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BuildJob' +type Jenkins_BuildJob_Call struct { + *mock.Call +} + +// BuildJob is a helper method to define mock.On call +// - ctx context.Context +// - name string +// - params map[string]string +func (_e *Jenkins_Expecter) BuildJob(ctx interface{}, name interface{}, params interface{}) *Jenkins_BuildJob_Call { + return &Jenkins_BuildJob_Call{Call: _e.mock.On("BuildJob", ctx, name, params)} +} + +func (_c *Jenkins_BuildJob_Call) Run(run func(ctx context.Context, name string, params map[string]string)) *Jenkins_BuildJob_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(map[string]string)) + }) + return _c +} + +func (_c *Jenkins_BuildJob_Call) Return(_a0 int64, _a1 error) *Jenkins_BuildJob_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Jenkins_BuildJob_Call) RunAndReturn(run func(context.Context, string, map[string]string) (int64, error)) *Jenkins_BuildJob_Call { + _c.Call.Return(run) + return _c +} + // GetBuildFromQueueID provides a mock function with given fields: ctx, job, queueid func (_m *Jenkins) GetBuildFromQueueID(ctx context.Context, job *gojenkins.Job, queueid int64) (*gojenkins.Build, error) { ret := _m.Called(ctx, job, queueid) + if len(ret) == 0 { + panic("no return value specified for GetBuildFromQueueID") + } + var r0 *gojenkins.Build + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *gojenkins.Job, int64) (*gojenkins.Build, error)); ok { + return rf(ctx, job, queueid) + } if rf, ok := ret.Get(0).(func(context.Context, *gojenkins.Job, int64) *gojenkins.Build); ok { r0 = rf(ctx, job, queueid) } else { @@ -49,7 +102,6 @@ func (_m *Jenkins) GetBuildFromQueueID(ctx context.Context, job *gojenkins.Job, } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *gojenkins.Job, int64) error); ok { r1 = rf(ctx, job, queueid) } else { @@ -59,10 +111,44 @@ func (_m *Jenkins) GetBuildFromQueueID(ctx context.Context, job *gojenkins.Job, return r0, r1 } +// Jenkins_GetBuildFromQueueID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBuildFromQueueID' +type Jenkins_GetBuildFromQueueID_Call struct { + *mock.Call +} + +// GetBuildFromQueueID is a helper method to define mock.On call +// - ctx context.Context +// - job *gojenkins.Job +// - queueid int64 +func (_e *Jenkins_Expecter) GetBuildFromQueueID(ctx interface{}, job interface{}, queueid interface{}) *Jenkins_GetBuildFromQueueID_Call { + return &Jenkins_GetBuildFromQueueID_Call{Call: _e.mock.On("GetBuildFromQueueID", ctx, job, queueid)} +} + +func (_c *Jenkins_GetBuildFromQueueID_Call) Run(run func(ctx context.Context, job *gojenkins.Job, queueid int64)) *Jenkins_GetBuildFromQueueID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*gojenkins.Job), args[2].(int64)) + }) + return _c +} + +func (_c *Jenkins_GetBuildFromQueueID_Call) Return(_a0 *gojenkins.Build, _a1 error) *Jenkins_GetBuildFromQueueID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Jenkins_GetBuildFromQueueID_Call) RunAndReturn(run func(context.Context, *gojenkins.Job, int64) (*gojenkins.Build, error)) *Jenkins_GetBuildFromQueueID_Call { + _c.Call.Return(run) + return _c +} + // GetJobObj provides a mock function with given fields: ctx, name func (_m *Jenkins) GetJobObj(ctx context.Context, name string) *gojenkins.Job { ret := _m.Called(ctx, name) + if len(ret) == 0 { + panic("no return value specified for GetJobObj") + } + var r0 *gojenkins.Job if rf, ok := ret.Get(0).(func(context.Context, string) *gojenkins.Job); ok { r0 = rf(ctx, name) @@ -74,3 +160,46 @@ func (_m *Jenkins) GetJobObj(ctx context.Context, name string) *gojenkins.Job { return r0 } + +// Jenkins_GetJobObj_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetJobObj' +type Jenkins_GetJobObj_Call struct { + *mock.Call +} + +// GetJobObj is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *Jenkins_Expecter) GetJobObj(ctx interface{}, name interface{}) *Jenkins_GetJobObj_Call { + return &Jenkins_GetJobObj_Call{Call: _e.mock.On("GetJobObj", ctx, name)} +} + +func (_c *Jenkins_GetJobObj_Call) Run(run func(ctx context.Context, name string)) *Jenkins_GetJobObj_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Jenkins_GetJobObj_Call) Return(_a0 *gojenkins.Job) *Jenkins_GetJobObj_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Jenkins_GetJobObj_Call) RunAndReturn(run func(context.Context, string) *gojenkins.Job) *Jenkins_GetJobObj_Call { + _c.Call.Return(run) + return _c +} + +// NewJenkins creates a new instance of Jenkins. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewJenkins(t interface { + mock.TestingT + Cleanup(func()) +}) *Jenkins { + mock := &Jenkins{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/jenkins/mocks/Job.go b/pkg/jenkins/mocks/Job.go index 729c7581c4..89cb925cd8 100644 --- a/pkg/jenkins/mocks/Job.go +++ b/pkg/jenkins/mocks/Job.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.7.5. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks @@ -15,10 +15,22 @@ type Job struct { mock.Mock } +type Job_Expecter struct { + mock *mock.Mock +} + +func (_m *Job) EXPECT() *Job_Expecter { + return &Job_Expecter{mock: &_m.Mock} +} + // GetJob provides a mock function with given fields: func (_m *Job) GetJob() *gojenkins.Job { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for GetJob") + } + var r0 *gojenkins.Job if rf, ok := ret.Get(0).(func() *gojenkins.Job); ok { r0 = rf() @@ -31,18 +43,52 @@ func (_m *Job) GetJob() *gojenkins.Job { return r0 } +// Job_GetJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetJob' +type Job_GetJob_Call struct { + *mock.Call +} + +// GetJob is a helper method to define mock.On call +func (_e *Job_Expecter) GetJob() *Job_GetJob_Call { + return &Job_GetJob_Call{Call: _e.mock.On("GetJob")} +} + +func (_c *Job_GetJob_Call) Run(run func()) *Job_GetJob_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Job_GetJob_Call) Return(_a0 *gojenkins.Job) *Job_GetJob_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Job_GetJob_Call) RunAndReturn(run func() *gojenkins.Job) *Job_GetJob_Call { + _c.Call.Return(run) + return _c +} + // InvokeSimple provides a mock function with given fields: ctx, params func (_m *Job) InvokeSimple(ctx context.Context, params map[string]string) (int64, error) { ret := _m.Called(ctx, params) + if len(ret) == 0 { + panic("no return value specified for InvokeSimple") + } + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, map[string]string) (int64, error)); ok { + return rf(ctx, params) + } if rf, ok := ret.Get(0).(func(context.Context, map[string]string) int64); ok { r0 = rf(ctx, params) } else { r0 = ret.Get(0).(int64) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, map[string]string) error); ok { r1 = rf(ctx, params) } else { @@ -52,18 +98,54 @@ func (_m *Job) InvokeSimple(ctx context.Context, params map[string]string) (int6 return r0, r1 } +// Job_InvokeSimple_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InvokeSimple' +type Job_InvokeSimple_Call struct { + *mock.Call +} + +// InvokeSimple is a helper method to define mock.On call +// - ctx context.Context +// - params map[string]string +func (_e *Job_Expecter) InvokeSimple(ctx interface{}, params interface{}) *Job_InvokeSimple_Call { + return &Job_InvokeSimple_Call{Call: _e.mock.On("InvokeSimple", ctx, params)} +} + +func (_c *Job_InvokeSimple_Call) Run(run func(ctx context.Context, params map[string]string)) *Job_InvokeSimple_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(map[string]string)) + }) + return _c +} + +func (_c *Job_InvokeSimple_Call) Return(_a0 int64, _a1 error) *Job_InvokeSimple_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Job_InvokeSimple_Call) RunAndReturn(run func(context.Context, map[string]string) (int64, error)) *Job_InvokeSimple_Call { + _c.Call.Return(run) + return _c +} + // Poll provides a mock function with given fields: _a0 func (_m *Job) Poll(_a0 context.Context) (int, error) { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Poll") + } + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (int, error)); ok { + return rf(_a0) + } if rf, ok := ret.Get(0).(func(context.Context) int); ok { r0 = rf(_a0) } else { r0 = ret.Get(0).(int) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context) error); ok { r1 = rf(_a0) } else { @@ -72,3 +154,45 @@ func (_m *Job) Poll(_a0 context.Context) (int, error) { return r0, r1 } + +// Job_Poll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Poll' +type Job_Poll_Call struct { + *mock.Call +} + +// Poll is a helper method to define mock.On call +// - _a0 context.Context +func (_e *Job_Expecter) Poll(_a0 interface{}) *Job_Poll_Call { + return &Job_Poll_Call{Call: _e.mock.On("Poll", _a0)} +} + +func (_c *Job_Poll_Call) Run(run func(_a0 context.Context)) *Job_Poll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *Job_Poll_Call) Return(_a0 int, _a1 error) *Job_Poll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Job_Poll_Call) RunAndReturn(run func(context.Context) (int, error)) *Job_Poll_Call { + _c.Call.Return(run) + return _c +} + +// NewJob creates a new instance of Job. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewJob(t interface { + mock.TestingT + Cleanup(func()) +}) *Job { + mock := &Job{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/jenkins/mocks/Task.go b/pkg/jenkins/mocks/Task.go index 9efa542e1a..fa8e01681f 100644 --- a/pkg/jenkins/mocks/Task.go +++ b/pkg/jenkins/mocks/Task.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.7.5. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks @@ -15,18 +15,33 @@ type Task struct { mock.Mock } +type Task_Expecter struct { + mock *mock.Mock +} + +func (_m *Task) EXPECT() *Task_Expecter { + return &Task_Expecter{mock: &_m.Mock} +} + // BuildNumber provides a mock function with given fields: func (_m *Task) BuildNumber() (int64, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for BuildNumber") + } + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func() (int64, error)); ok { + return rf() + } if rf, ok := ret.Get(0).(func() int64); ok { r0 = rf() } else { r0 = ret.Get(0).(int64) } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -36,10 +51,41 @@ func (_m *Task) BuildNumber() (int64, error) { return r0, r1 } +// Task_BuildNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BuildNumber' +type Task_BuildNumber_Call struct { + *mock.Call +} + +// BuildNumber is a helper method to define mock.On call +func (_e *Task_Expecter) BuildNumber() *Task_BuildNumber_Call { + return &Task_BuildNumber_Call{Call: _e.mock.On("BuildNumber")} +} + +func (_c *Task_BuildNumber_Call) Run(run func()) *Task_BuildNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Task_BuildNumber_Call) Return(_a0 int64, _a1 error) *Task_BuildNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Task_BuildNumber_Call) RunAndReturn(run func() (int64, error)) *Task_BuildNumber_Call { + _c.Call.Return(run) + return _c +} + // HasStarted provides a mock function with given fields: func (_m *Task) HasStarted() bool { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for HasStarted") + } + var r0 bool if rf, ok := ret.Get(0).(func() bool); ok { r0 = rf() @@ -50,18 +96,52 @@ func (_m *Task) HasStarted() bool { return r0 } +// Task_HasStarted_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasStarted' +type Task_HasStarted_Call struct { + *mock.Call +} + +// HasStarted is a helper method to define mock.On call +func (_e *Task_Expecter) HasStarted() *Task_HasStarted_Call { + return &Task_HasStarted_Call{Call: _e.mock.On("HasStarted")} +} + +func (_c *Task_HasStarted_Call) Run(run func()) *Task_HasStarted_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Task_HasStarted_Call) Return(_a0 bool) *Task_HasStarted_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Task_HasStarted_Call) RunAndReturn(run func() bool) *Task_HasStarted_Call { + _c.Call.Return(run) + return _c +} + // Poll provides a mock function with given fields: _a0 func (_m *Task) Poll(_a0 context.Context) (int, error) { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Poll") + } + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (int, error)); ok { + return rf(_a0) + } if rf, ok := ret.Get(0).(func(context.Context) int); ok { r0 = rf(_a0) } else { r0 = ret.Get(0).(int) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context) error); ok { r1 = rf(_a0) } else { @@ -71,18 +151,53 @@ func (_m *Task) Poll(_a0 context.Context) (int, error) { return r0, r1 } +// Task_Poll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Poll' +type Task_Poll_Call struct { + *mock.Call +} + +// Poll is a helper method to define mock.On call +// - _a0 context.Context +func (_e *Task_Expecter) Poll(_a0 interface{}) *Task_Poll_Call { + return &Task_Poll_Call{Call: _e.mock.On("Poll", _a0)} +} + +func (_c *Task_Poll_Call) Run(run func(_a0 context.Context)) *Task_Poll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *Task_Poll_Call) Return(_a0 int, _a1 error) *Task_Poll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Task_Poll_Call) RunAndReturn(run func(context.Context) (int, error)) *Task_Poll_Call { + _c.Call.Return(run) + return _c +} + // WaitToStart provides a mock function with given fields: ctx, pollInterval func (_m *Task) WaitToStart(ctx context.Context, pollInterval time.Duration) (int64, error) { ret := _m.Called(ctx, pollInterval) + if len(ret) == 0 { + panic("no return value specified for WaitToStart") + } + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, time.Duration) (int64, error)); ok { + return rf(ctx, pollInterval) + } if rf, ok := ret.Get(0).(func(context.Context, time.Duration) int64); ok { r0 = rf(ctx, pollInterval) } else { r0 = ret.Get(0).(int64) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, time.Duration) error); ok { r1 = rf(ctx, pollInterval) } else { @@ -91,3 +206,46 @@ func (_m *Task) WaitToStart(ctx context.Context, pollInterval time.Duration) (in return r0, r1 } + +// Task_WaitToStart_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WaitToStart' +type Task_WaitToStart_Call struct { + *mock.Call +} + +// WaitToStart is a helper method to define mock.On call +// - ctx context.Context +// - pollInterval time.Duration +func (_e *Task_Expecter) WaitToStart(ctx interface{}, pollInterval interface{}) *Task_WaitToStart_Call { + return &Task_WaitToStart_Call{Call: _e.mock.On("WaitToStart", ctx, pollInterval)} +} + +func (_c *Task_WaitToStart_Call) Run(run func(ctx context.Context, pollInterval time.Duration)) *Task_WaitToStart_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(time.Duration)) + }) + return _c +} + +func (_c *Task_WaitToStart_Call) Return(_a0 int64, _a1 error) *Task_WaitToStart_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Task_WaitToStart_Call) RunAndReturn(run func(context.Context, time.Duration) (int64, error)) *Task_WaitToStart_Call { + _c.Call.Return(run) + return _c +} + +// NewTask creates a new instance of Task. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTask(t interface { + mock.TestingT + Cleanup(func()) +}) *Task { + mock := &Task{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/jenkins/task.go b/pkg/jenkins/task.go index deaa5ef51e..a796e198c3 100644 --- a/pkg/jenkins/task.go +++ b/pkg/jenkins/task.go @@ -9,7 +9,6 @@ import ( ) // Task is an interface to abstract gojenkins.Task. -// mock generated with: mockery --name Task --dir pkg/jenkins --output pkg/jenkins/mocks type Task interface { Poll(context.Context) (int, error) BuildNumber() (int64, error) diff --git a/pkg/kubernetes/mocks/HelmExecutor.go b/pkg/kubernetes/mocks/HelmExecutor.go index 4232366115..38cb8de580 100644 --- a/pkg/kubernetes/mocks/HelmExecutor.go +++ b/pkg/kubernetes/mocks/HelmExecutor.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.43.0. DO NOT EDIT. package mocks @@ -9,10 +9,22 @@ type HelmExecutor struct { mock.Mock } +type HelmExecutor_Expecter struct { + mock *mock.Mock +} + +func (_m *HelmExecutor) EXPECT() *HelmExecutor_Expecter { + return &HelmExecutor_Expecter{mock: &_m.Mock} +} + // RunHelmDependency provides a mock function with given fields: func (_m *HelmExecutor) RunHelmDependency() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for RunHelmDependency") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -23,10 +35,41 @@ func (_m *HelmExecutor) RunHelmDependency() error { return r0 } +// HelmExecutor_RunHelmDependency_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RunHelmDependency' +type HelmExecutor_RunHelmDependency_Call struct { + *mock.Call +} + +// RunHelmDependency is a helper method to define mock.On call +func (_e *HelmExecutor_Expecter) RunHelmDependency() *HelmExecutor_RunHelmDependency_Call { + return &HelmExecutor_RunHelmDependency_Call{Call: _e.mock.On("RunHelmDependency")} +} + +func (_c *HelmExecutor_RunHelmDependency_Call) Run(run func()) *HelmExecutor_RunHelmDependency_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *HelmExecutor_RunHelmDependency_Call) Return(_a0 error) *HelmExecutor_RunHelmDependency_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HelmExecutor_RunHelmDependency_Call) RunAndReturn(run func() error) *HelmExecutor_RunHelmDependency_Call { + _c.Call.Return(run) + return _c +} + // RunHelmInstall provides a mock function with given fields: func (_m *HelmExecutor) RunHelmInstall() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for RunHelmInstall") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -37,10 +80,41 @@ func (_m *HelmExecutor) RunHelmInstall() error { return r0 } +// HelmExecutor_RunHelmInstall_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RunHelmInstall' +type HelmExecutor_RunHelmInstall_Call struct { + *mock.Call +} + +// RunHelmInstall is a helper method to define mock.On call +func (_e *HelmExecutor_Expecter) RunHelmInstall() *HelmExecutor_RunHelmInstall_Call { + return &HelmExecutor_RunHelmInstall_Call{Call: _e.mock.On("RunHelmInstall")} +} + +func (_c *HelmExecutor_RunHelmInstall_Call) Run(run func()) *HelmExecutor_RunHelmInstall_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *HelmExecutor_RunHelmInstall_Call) Return(_a0 error) *HelmExecutor_RunHelmInstall_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HelmExecutor_RunHelmInstall_Call) RunAndReturn(run func() error) *HelmExecutor_RunHelmInstall_Call { + _c.Call.Return(run) + return _c +} + // RunHelmLint provides a mock function with given fields: func (_m *HelmExecutor) RunHelmLint() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for RunHelmLint") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -51,18 +125,52 @@ func (_m *HelmExecutor) RunHelmLint() error { return r0 } +// HelmExecutor_RunHelmLint_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RunHelmLint' +type HelmExecutor_RunHelmLint_Call struct { + *mock.Call +} + +// RunHelmLint is a helper method to define mock.On call +func (_e *HelmExecutor_Expecter) RunHelmLint() *HelmExecutor_RunHelmLint_Call { + return &HelmExecutor_RunHelmLint_Call{Call: _e.mock.On("RunHelmLint")} +} + +func (_c *HelmExecutor_RunHelmLint_Call) Run(run func()) *HelmExecutor_RunHelmLint_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *HelmExecutor_RunHelmLint_Call) Return(_a0 error) *HelmExecutor_RunHelmLint_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HelmExecutor_RunHelmLint_Call) RunAndReturn(run func() error) *HelmExecutor_RunHelmLint_Call { + _c.Call.Return(run) + return _c +} + // RunHelmPublish provides a mock function with given fields: func (_m *HelmExecutor) RunHelmPublish() (string, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for RunHelmPublish") + } + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func() (string, error)); ok { + return rf() + } if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { r0 = ret.Get(0).(string) } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -72,10 +180,41 @@ func (_m *HelmExecutor) RunHelmPublish() (string, error) { return r0, r1 } +// HelmExecutor_RunHelmPublish_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RunHelmPublish' +type HelmExecutor_RunHelmPublish_Call struct { + *mock.Call +} + +// RunHelmPublish is a helper method to define mock.On call +func (_e *HelmExecutor_Expecter) RunHelmPublish() *HelmExecutor_RunHelmPublish_Call { + return &HelmExecutor_RunHelmPublish_Call{Call: _e.mock.On("RunHelmPublish")} +} + +func (_c *HelmExecutor_RunHelmPublish_Call) Run(run func()) *HelmExecutor_RunHelmPublish_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *HelmExecutor_RunHelmPublish_Call) Return(_a0 string, _a1 error) *HelmExecutor_RunHelmPublish_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *HelmExecutor_RunHelmPublish_Call) RunAndReturn(run func() (string, error)) *HelmExecutor_RunHelmPublish_Call { + _c.Call.Return(run) + return _c +} + // RunHelmTest provides a mock function with given fields: func (_m *HelmExecutor) RunHelmTest() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for RunHelmTest") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -86,10 +225,41 @@ func (_m *HelmExecutor) RunHelmTest() error { return r0 } +// HelmExecutor_RunHelmTest_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RunHelmTest' +type HelmExecutor_RunHelmTest_Call struct { + *mock.Call +} + +// RunHelmTest is a helper method to define mock.On call +func (_e *HelmExecutor_Expecter) RunHelmTest() *HelmExecutor_RunHelmTest_Call { + return &HelmExecutor_RunHelmTest_Call{Call: _e.mock.On("RunHelmTest")} +} + +func (_c *HelmExecutor_RunHelmTest_Call) Run(run func()) *HelmExecutor_RunHelmTest_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *HelmExecutor_RunHelmTest_Call) Return(_a0 error) *HelmExecutor_RunHelmTest_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HelmExecutor_RunHelmTest_Call) RunAndReturn(run func() error) *HelmExecutor_RunHelmTest_Call { + _c.Call.Return(run) + return _c +} + // RunHelmUninstall provides a mock function with given fields: func (_m *HelmExecutor) RunHelmUninstall() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for RunHelmUninstall") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -100,10 +270,41 @@ func (_m *HelmExecutor) RunHelmUninstall() error { return r0 } +// HelmExecutor_RunHelmUninstall_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RunHelmUninstall' +type HelmExecutor_RunHelmUninstall_Call struct { + *mock.Call +} + +// RunHelmUninstall is a helper method to define mock.On call +func (_e *HelmExecutor_Expecter) RunHelmUninstall() *HelmExecutor_RunHelmUninstall_Call { + return &HelmExecutor_RunHelmUninstall_Call{Call: _e.mock.On("RunHelmUninstall")} +} + +func (_c *HelmExecutor_RunHelmUninstall_Call) Run(run func()) *HelmExecutor_RunHelmUninstall_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *HelmExecutor_RunHelmUninstall_Call) Return(_a0 error) *HelmExecutor_RunHelmUninstall_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HelmExecutor_RunHelmUninstall_Call) RunAndReturn(run func() error) *HelmExecutor_RunHelmUninstall_Call { + _c.Call.Return(run) + return _c +} + // RunHelmUpgrade provides a mock function with given fields: func (_m *HelmExecutor) RunHelmUpgrade() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for RunHelmUpgrade") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -114,13 +315,39 @@ func (_m *HelmExecutor) RunHelmUpgrade() error { return r0 } -type mockConstructorTestingTNewHelmExecutor interface { - mock.TestingT - Cleanup(func()) +// HelmExecutor_RunHelmUpgrade_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RunHelmUpgrade' +type HelmExecutor_RunHelmUpgrade_Call struct { + *mock.Call +} + +// RunHelmUpgrade is a helper method to define mock.On call +func (_e *HelmExecutor_Expecter) RunHelmUpgrade() *HelmExecutor_RunHelmUpgrade_Call { + return &HelmExecutor_RunHelmUpgrade_Call{Call: _e.mock.On("RunHelmUpgrade")} +} + +func (_c *HelmExecutor_RunHelmUpgrade_Call) Run(run func()) *HelmExecutor_RunHelmUpgrade_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *HelmExecutor_RunHelmUpgrade_Call) Return(_a0 error) *HelmExecutor_RunHelmUpgrade_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *HelmExecutor_RunHelmUpgrade_Call) RunAndReturn(run func() error) *HelmExecutor_RunHelmUpgrade_Call { + _c.Call.Return(run) + return _c } // NewHelmExecutor creates a new instance of HelmExecutor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewHelmExecutor(t mockConstructorTestingTNewHelmExecutor) *HelmExecutor { +// The first argument is typically a *testing.T value. +func NewHelmExecutor(t interface { + mock.TestingT + Cleanup(func()) +}) *HelmExecutor { mock := &HelmExecutor{} mock.Mock.Test(t) From df1db9eed77475f3aece0531eab6458b6f62395d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20K=C3=B6rner?= <70266685+tiloKo@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:51:58 +0200 Subject: [PATCH 2/5] ABAP aakaas and build steps: Parse odata error json (#4946) * parseErrorBody Implemented --- pkg/abap/build/connector.go | 10 +-- pkg/abap/build/gwError.go | 68 +++++++++++++++++++ pkg/abap/build/gwError_test.go | 117 +++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 pkg/abap/build/gwError.go create mode 100644 pkg/abap/build/gwError_test.go diff --git a/pkg/abap/build/connector.go b/pkg/abap/build/connector.go index 2ee1109664..a5d52accdf 100644 --- a/pkg/abap/build/connector.go +++ b/pkg/abap/build/connector.go @@ -66,7 +66,7 @@ func (conn *Connector) GetToken(appendum string) error { } defer response.Body.Close() errorbody, _ := io.ReadAll(response.Body) - return errors.Wrapf(err, "Fetching X-CSRF-Token failed: %v", string(errorbody)) + return errors.Wrapf(err, "Fetching X-CSRF-Token failed: %v", extractErrorStackFromJsonData(errorbody)) } defer response.Body.Close() @@ -85,7 +85,7 @@ func (conn Connector) Get(appendum string) ([]byte, error) { } defer response.Body.Close() errorbody, _ := io.ReadAll(response.Body) - return errorbody, errors.Wrapf(err, "Get failed: %v", string(errorbody)) + return errorbody, errors.Wrapf(err, "Get failed: %v", extractErrorStackFromJsonData(errorbody)) } defer response.Body.Close() @@ -109,7 +109,7 @@ func (conn Connector) Post(appendum string, importBody string) ([]byte, error) { } defer response.Body.Close() errorbody, _ := io.ReadAll(response.Body) - return errorbody, errors.Wrapf(err, "Post failed: %v", string(errorbody)) + return errorbody, errors.Wrapf(err, "Post failed: %v", extractErrorStackFromJsonData(errorbody)) } defer response.Body.Close() @@ -268,7 +268,7 @@ func (conn Connector) UploadSarFile(appendum string, sarFile []byte) error { if err != nil { defer response.Body.Close() errorbody, _ := io.ReadAll(response.Body) - return errors.Wrapf(err, "Upload of SAR file failed: %v", string(errorbody)) + return errors.Wrapf(err, "Upload of SAR file failed: %v", extractErrorStackFromJsonData(errorbody)) } defer response.Body.Close() return nil @@ -304,7 +304,7 @@ func (conn Connector) UploadSarFileInChunks(appendum string, fileName string, sa if response != nil && response.Body != nil { errorbody, _ := io.ReadAll(response.Body) response.Body.Close() - return errors.Wrapf(err, "Upload of SAR file failed: %v", string(errorbody)) + return errors.Wrapf(err, "Upload of SAR file failed: %v", extractErrorStackFromJsonData(errorbody)) } else { return err } diff --git a/pkg/abap/build/gwError.go b/pkg/abap/build/gwError.go new file mode 100644 index 0000000000..ee019c08d6 --- /dev/null +++ b/pkg/abap/build/gwError.go @@ -0,0 +1,68 @@ +package build + +import ( + "encoding/json" + "fmt" + "strings" +) + +type GW_error struct { + Error struct { + Code string + Message struct { + Lang string + Value string + } + Innererror struct { + Application struct { + Component_id string + Service_namespace string + Service_id string + Service_version string + } + Transactionid string + Timestamp string + Error_Resolution struct { + SAP_Transaction string + SAP_Note string + } + Errordetails []struct { + ContentID string + Code string + Message string + Propertyref string + Severity string + Transition bool + Target string + } + } + } +} + +func extractErrorStackFromJsonData(jsonData []byte) string { + my_error := new(GW_error) + if err := my_error.FromJson(jsonData); err != nil { + return string(jsonData) + } + return my_error.ExtractStack() +} + +func (my_error *GW_error) FromJson(inputJson []byte) error { + if err := json.Unmarshal(inputJson, my_error); err != nil { + return err + } + return nil +} + +func (my_error *GW_error) ExtractStack() string { + var stack strings.Builder + var previousMessage string + for index, detail := range my_error.Error.Innererror.Errordetails { + if previousMessage == detail.Message { + continue + } + previousMessage = detail.Message + stack.WriteString(fmt.Sprintf("[%v] %s\n", index, detail.Message)) + } + return stack.String() +} diff --git a/pkg/abap/build/gwError_test.go b/pkg/abap/build/gwError_test.go new file mode 100644 index 0000000000..2c85e39a8b --- /dev/null +++ b/pkg/abap/build/gwError_test.go @@ -0,0 +1,117 @@ +package build + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestExtractErrorStack(t *testing.T) { + t.Run("Valid Json String", func(t *testing.T) { + //act + errorString := extractErrorStackFromJsonData([]byte(validResponse)) + //assert + assert.Equal(t, `[0] Data Provider: SOME_PACKAGE and 0 other packages do not exist in system XXX +[1] Reading SCs of Packages failed +`, errorString) + }) + + t.Run("No Json String", func(t *testing.T) { + //arrange + var noJson = "ERROR 404: Unauthorized" + //act + errorString := extractErrorStackFromJsonData([]byte(noJson)) + //assert + assert.Equal(t, noJson, errorString) + }) + + t.Run("step by step", func(t *testing.T) { + my_error := new(GW_error) + err := my_error.FromJson([]byte(validResponse)) + assert.NoError(t, err) + + assert.Equal(t, "/IWBEP/CM_MGW_RT/022", my_error.Error.Code) + assert.Equal(t, "en", my_error.Error.Message.Lang) + assert.Equal(t, "Data Provider: SOME_PACKAGE and 0 other packages do not exist in system XXX", my_error.Error.Message.Value) + assert.Equal(t, "BC-UPG-ADDON", my_error.Error.Innererror.Application.Component_id) + assert.Equal(t, "/BUILD/", my_error.Error.Innererror.Application.Service_namespace) + assert.Equal(t, "CORE_SRV", my_error.Error.Innererror.Application.Service_id) + assert.Equal(t, "0001", my_error.Error.Innererror.Application.Service_version) + assert.Equal(t, "1801B32D512B00C0E0066215B8D723B5", my_error.Error.Innererror.Transactionid) + assert.Equal(t, "", my_error.Error.Innererror.Timestamp) + assert.Equal(t, "", my_error.Error.Innererror.Error_Resolution.SAP_Transaction) + assert.Equal(t, "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)", my_error.Error.Innererror.Error_Resolution.SAP_Note) + assert.Equal(t, 3, len(my_error.Error.Innererror.Errordetails)) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[0].ContentID) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[0].Propertyref) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[0].Target) + assert.Equal(t, "error", my_error.Error.Innererror.Errordetails[0].Severity) + assert.Equal(t, false, my_error.Error.Innererror.Errordetails[0].Transition) + assert.Equal(t, "/BUILD/CX_EXTERNAL", my_error.Error.Innererror.Errordetails[0].Code) + assert.Equal(t, "Data Provider: SOME_PACKAGE and 0 other packages do not exist in system XXX", my_error.Error.Innererror.Errordetails[0].Message) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[1].ContentID) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[1].Propertyref) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[1].Target) + assert.Equal(t, "error", my_error.Error.Innererror.Errordetails[1].Severity) + assert.Equal(t, false, my_error.Error.Innererror.Errordetails[1].Transition) + assert.Equal(t, "/BUILD/CX_BUILD", my_error.Error.Innererror.Errordetails[1].Code) + assert.Equal(t, "Reading SCs of Packages failed", my_error.Error.Innererror.Errordetails[1].Message) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[2].ContentID) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[2].Propertyref) + assert.Equal(t, "", my_error.Error.Innererror.Errordetails[2].Target) + assert.Equal(t, "error", my_error.Error.Innererror.Errordetails[2].Severity) + assert.Equal(t, false, my_error.Error.Innererror.Errordetails[2].Transition) + assert.Equal(t, "/IWBEP/CX_MGW_BUSI_EXCEPTION", my_error.Error.Innererror.Errordetails[2].Code) + assert.Equal(t, "Reading SCs of Packages failed", my_error.Error.Innererror.Errordetails[2].Message) + }) +} + +var validResponse = `{ + "error": { + "code": "/IWBEP/CM_MGW_RT/022", + "message": { + "lang": "en", + "value": "Data Provider: SOME_PACKAGE and 0 other packages do not exist in system XXX" + }, + "innererror": { + "application": { + "component_id": "BC-UPG-ADDON", + "service_namespace": "/BUILD/", + "service_id": "CORE_SRV", + "service_version": "0001" + }, + "transactionid": "1801B32D512B00C0E0066215B8D723B5", + "timestamp": "", + "Error_Resolution": { + "SAP_Transaction": "", + "SAP_Note": "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)" + }, + "errordetails": [{ + "ContentID": "", + "code": "/BUILD/CX_EXTERNAL", + "message": "Data Provider: SOME_PACKAGE and 0 other packages do not exist in system XXX", + "propertyref": "", + "severity": "error", + "transition": false, + "target": "" + }, { + "ContentID": "", + "code": "/BUILD/CX_BUILD", + "message": "Reading SCs of Packages failed", + "propertyref": "", + "severity": "error", + "transition": false, + "target": "" + }, { + "ContentID": "", + "code": "/IWBEP/CX_MGW_BUSI_EXCEPTION", + "message": "Reading SCs of Packages failed", + "propertyref": "", + "severity": "error", + "transition": false, + "target": "" + } + ] + } + } +}` From e2a5b0928a8ec653f6bd7b3700b5b97ba25e60f9 Mon Sep 17 00:00:00 2001 From: Andrei Kireev Date: Thu, 6 Jun 2024 09:20:08 +0200 Subject: [PATCH 3/5] feat(detectExecuteScan) Added npm install step for detectExectueScan (#4949) * Added npm install step for detectExectueScan --- cmd/detectExecuteScan.go | 17 ++++++++++++ cmd/detectExecuteScan_generated.go | 33 +++++++++++++++++++++++ resources/metadata/detectExecuteScan.yaml | 26 ++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/cmd/detectExecuteScan.go b/cmd/detectExecuteScan.go index eb608f0c63..a6c07d335d 100644 --- a/cmd/detectExecuteScan.go +++ b/cmd/detectExecuteScan.go @@ -20,6 +20,7 @@ import ( piperhttp "github.com/SAP/jenkins-library/pkg/http" "github.com/SAP/jenkins-library/pkg/log" "github.com/SAP/jenkins-library/pkg/maven" + "github.com/SAP/jenkins-library/pkg/npm" "github.com/SAP/jenkins-library/pkg/orchestrator" "github.com/SAP/jenkins-library/pkg/piperutils" "github.com/SAP/jenkins-library/pkg/reporting" @@ -213,6 +214,22 @@ func runDetect(ctx context.Context, config detectExecuteScanOptions, utils detec } } + // Install NPM dependencies + if config.InstallNPM { + log.Entry().Debugf("running npm install") + npmExecutor := npm.NewExecutor(npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry}) + + buildDescriptorList := config.BuildDescriptorList + if len(buildDescriptorList) == 0 { + buildDescriptorList = []string{"package.json"} + } + + err := npmExecutor.InstallAllDependencies(buildDescriptorList) + if err != nil { + return err + } + } + // for MTA if config.BuildMTA { log.Entry().Infof("running MTA Build") diff --git a/cmd/detectExecuteScan_generated.go b/cmd/detectExecuteScan_generated.go index 7546438d9d..52db429574 100644 --- a/cmd/detectExecuteScan_generated.go +++ b/cmd/detectExecuteScan_generated.go @@ -42,6 +42,9 @@ type detectExecuteScanOptions struct { InstallArtifacts bool `json:"installArtifacts,omitempty"` BuildMaven bool `json:"buildMaven,omitempty"` BuildMTA bool `json:"buildMTA,omitempty"` + InstallNPM bool `json:"installNPM,omitempty"` + DefaultNpmRegistry string `json:"defaultNpmRegistry,omitempty"` + BuildDescriptorList []string `json:"buildDescriptorList,omitempty"` EnableDiagnostics bool `json:"enableDiagnostics,omitempty"` GenerateReportsForEmptyProjects bool `json:"generateReportsForEmptyProjects,omitempty"` MtaPlatform string `json:"mtaPlatform,omitempty"` @@ -298,6 +301,9 @@ func addDetectExecuteScanFlags(cmd *cobra.Command, stepConfig *detectExecuteScan cmd.Flags().BoolVar(&stepConfig.InstallArtifacts, "installArtifacts", false, "If enabled, it will install all artifacts to the local maven repository to make them available before running detect. This is required if any maven module has dependencies to other modules in the repository and they were not installed before.") cmd.Flags().BoolVar(&stepConfig.BuildMaven, "buildMaven", false, "Experiment parameter for maven multi-modules projects building") cmd.Flags().BoolVar(&stepConfig.BuildMTA, "buildMTA", false, "Experiment parameter for MTA projects building") + cmd.Flags().BoolVar(&stepConfig.InstallNPM, "installNPM", false, "Experiment parameter for downloading npm dependencies") + cmd.Flags().StringVar(&stepConfig.DefaultNpmRegistry, "defaultNpmRegistry", os.Getenv("PIPER_defaultNpmRegistry"), "URL of the npm registry to use. Defaults to https://registry.npmjs.org/") + cmd.Flags().StringSliceVar(&stepConfig.BuildDescriptorList, "buildDescriptorList", []string{}, "List of build descriptors and therefore modules for execution of the npm scripts. The elements have to be paths to the build descriptors.") cmd.Flags().BoolVar(&stepConfig.EnableDiagnostics, "enableDiagnostics", false, "Parameter to enable diagnostics file generation by detect script") cmd.Flags().BoolVar(&stepConfig.GenerateReportsForEmptyProjects, "generateReportsForEmptyProjects", false, "If enabled, it will generate reports for empty projects. This could be useful to see the compliance reports in Sirius") cmd.Flags().StringVar(&stepConfig.MtaPlatform, "mtaPlatform", `CF`, "The platform of the MTA project") @@ -552,6 +558,33 @@ func detectExecuteScanMetadata() config.StepData { Aliases: []config.Alias{}, Default: false, }, + { + Name: "installNPM", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"STEPS", "STAGES", "PARAMETERS"}, + Type: "bool", + Mandatory: false, + Aliases: []config.Alias{}, + Default: false, + }, + { + Name: "defaultNpmRegistry", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"PARAMETERS", "GENERAL", "STAGES", "STEPS"}, + Type: "string", + Mandatory: false, + Aliases: []config.Alias{{Name: "npm/defaultNpmRegistry"}}, + Default: os.Getenv("PIPER_defaultNpmRegistry"), + }, + { + Name: "buildDescriptorList", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, + Type: "[]string", + Mandatory: false, + Aliases: []config.Alias{}, + Default: []string{}, + }, { Name: "enableDiagnostics", ResourceRef: []config.ResourceReference{}, diff --git a/resources/metadata/detectExecuteScan.yaml b/resources/metadata/detectExecuteScan.yaml index d92bc5dba7..743ab2419e 100644 --- a/resources/metadata/detectExecuteScan.yaml +++ b/resources/metadata/detectExecuteScan.yaml @@ -266,6 +266,32 @@ spec: - STEPS - STAGES - PARAMETERS + - name: installNPM + type: bool + default: false + description: + "Experiment parameter for downloading npm dependencies" + scope: + - STEPS + - STAGES + - PARAMETERS + - name: defaultNpmRegistry + type: string + description: "URL of the npm registry to use. Defaults to https://registry.npmjs.org/" + scope: + - PARAMETERS + - GENERAL + - STAGES + - STEPS + aliases: + - name: npm/defaultNpmRegistry + - name: buildDescriptorList + type: "[]string" + description: List of build descriptors and therefore modules for execution of the npm scripts. The elements have to be paths to the build descriptors. + scope: + - PARAMETERS + - STAGES + - STEPS - name: enableDiagnostics type: bool default: false From 67ed27f07dc275d89ec1485b068fe9331aff6b4b Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Thu, 6 Jun 2024 14:14:03 +0200 Subject: [PATCH 4/5] added sed cmd to transform querySuite (#4945) * added sed cmd to transform querySuite * changed sh to bash * added checking os * fixed tests by mocking utils * fixed tests * renamed param --------- Co-authored-by: sumeet patil --- cmd/codeqlExecuteScan.go | 26 ++++++--- cmd/codeqlExecuteScan_generated.go | 11 ++++ cmd/codeqlExecuteScan_test.go | 66 ++++++++++++++++++----- resources/metadata/codeqlExecuteScan.yaml | 7 +++ 4 files changed, 91 insertions(+), 19 deletions(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index 546a310dd5..cd97f0a981 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -59,9 +59,23 @@ func codeqlExecuteScan(config codeqlExecuteScanOptions, telemetryData *telemetry influx.step_data.fields.codeql = true } -func appendCodeqlQuery(cmd []string, codeqlQuery string) []string { - if len(codeqlQuery) > 0 { - cmd = append(cmd, codeqlQuery) +func appendCodeqlQuerySuite(utils codeqlExecuteScanUtils, cmd []string, querySuite, transformString string) []string { + if len(querySuite) > 0 { + if len(transformString) > 0 { + var bufferOut, bufferErr bytes.Buffer + utils.Stdout(&bufferOut) + defer utils.Stdout(log.Writer()) + utils.Stderr(&bufferErr) + defer utils.Stderr(log.Writer()) + if err := utils.RunExecutable("sh", []string{"-c", fmt.Sprintf("echo %s | sed -E \"%s\"", querySuite, transformString)}...); err != nil { + log.Entry().WithError(err).Error("failed to transform querySuite") + e := bufferErr.String() + log.Entry().Error(e) + } else { + querySuite = strings.TrimSpace(bufferOut.String()) + } + } + cmd = append(cmd, querySuite) } return cmd @@ -271,7 +285,7 @@ func runGithubUploadResults(config *codeqlExecuteScanOptions, repoInfo *codeql.R func executeAnalysis(format, reportName string, customFlags map[string]string, config *codeqlExecuteScanOptions, utils codeqlExecuteScanUtils) ([]piperutils.Path, error) { moduleTargetPath := filepath.Join(config.ModulePath, "target") report := filepath.Join(moduleTargetPath, reportName) - cmd, err := prepareCmdForDatabaseAnalyze(customFlags, config, format, report) + cmd, err := prepareCmdForDatabaseAnalyze(utils, customFlags, config, format, report) if err != nil { log.Entry().Errorf("failed to prepare command for codeql database analyze (format=%s)", format) return nil, err @@ -323,11 +337,11 @@ func prepareCmdForDatabaseCreate(customFlags map[string]string, config *codeqlEx return cmd, nil } -func prepareCmdForDatabaseAnalyze(customFlags map[string]string, config *codeqlExecuteScanOptions, format, reportName string) ([]string, error) { +func prepareCmdForDatabaseAnalyze(utils codeqlExecuteScanUtils, customFlags map[string]string, config *codeqlExecuteScanOptions, format, reportName string) ([]string, error) { cmd := []string{"database", "analyze", "--format=" + format, "--output=" + reportName, config.Database} cmd = codeql.AppendThreadsAndRam(cmd, config.Threads, config.Ram, customFlags) cmd = codeql.AppendCustomFlags(cmd, customFlags) - cmd = appendCodeqlQuery(cmd, config.QuerySuite) + cmd = appendCodeqlQuerySuite(utils, cmd, config.QuerySuite, config.TransformQuerySuite) return cmd, nil } diff --git a/cmd/codeqlExecuteScan_generated.go b/cmd/codeqlExecuteScan_generated.go index bd4ac20aba..91e6118d12 100644 --- a/cmd/codeqlExecuteScan_generated.go +++ b/cmd/codeqlExecuteScan_generated.go @@ -46,6 +46,7 @@ type codeqlExecuteScanOptions struct { DatabaseCreateFlags string `json:"databaseCreateFlags,omitempty"` DatabaseAnalyzeFlags string `json:"databaseAnalyzeFlags,omitempty"` CustomCommand string `json:"customCommand,omitempty"` + TransformQuerySuite string `json:"transformQuerySuite,omitempty"` } type codeqlExecuteScanInflux struct { @@ -273,6 +274,7 @@ func addCodeqlExecuteScanFlags(cmd *cobra.Command, stepConfig *codeqlExecuteScan cmd.Flags().StringVar(&stepConfig.DatabaseCreateFlags, "databaseCreateFlags", os.Getenv("PIPER_databaseCreateFlags"), "A space-separated string of flags for the 'codeql database create' command.") cmd.Flags().StringVar(&stepConfig.DatabaseAnalyzeFlags, "databaseAnalyzeFlags", os.Getenv("PIPER_databaseAnalyzeFlags"), "A space-separated string of flags for the 'codeql database analyze' command.") cmd.Flags().StringVar(&stepConfig.CustomCommand, "customCommand", os.Getenv("PIPER_customCommand"), "A custom user-defined command to run between codeql analysis and results upload.") + cmd.Flags().StringVar(&stepConfig.TransformQuerySuite, "transformQuerySuite", os.Getenv("PIPER_transformQuerySuite"), "A transform string that will be applied to the querySuite using the sed command.") cmd.MarkFlagRequired("buildTool") } @@ -538,6 +540,15 @@ func codeqlExecuteScanMetadata() config.StepData { Aliases: []config.Alias{}, Default: os.Getenv("PIPER_customCommand"), }, + { + Name: "transformQuerySuite", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"STEPS", "STAGES", "PARAMETERS"}, + Type: "string", + Mandatory: false, + Aliases: []config.Alias{}, + Default: os.Getenv("PIPER_transformQuerySuite"), + }, }, }, Containers: []config.Container{ diff --git a/cmd/codeqlExecuteScan_test.go b/cmd/codeqlExecuteScan_test.go index 775ddea346..2270c6b106 100644 --- a/cmd/codeqlExecuteScan_test.go +++ b/cmd/codeqlExecuteScan_test.go @@ -4,6 +4,8 @@ package cmd import ( + "fmt" + "io" "os" "strings" "testing" @@ -21,7 +23,11 @@ type codeqlExecuteScanMockUtils struct { func newCodeqlExecuteScanTestsUtils() codeqlExecuteScanMockUtils { utils := codeqlExecuteScanMockUtils{ - ExecMockRunner: &mock.ExecMockRunner{}, + ExecMockRunner: &mock.ExecMockRunner{ + Stub: func(call string, stdoutReturn map[string]string, shouldFailOnCommand map[string]error, stdout io.Writer) error { + return nil + }, + }, FilesMock: &mock.FilesMock{}, HttpClientMock: &mock.HttpClientMock{}, } @@ -406,12 +412,13 @@ func TestPrepareCmdForDatabaseCreate(t *testing.T) { func TestPrepareCmdForDatabaseAnalyze(t *testing.T) { t.Parallel() + utils := codeqlExecuteScanMockUtils{} t.Run("No additional flags, no querySuite, sarif format", func(t *testing.T) { config := &codeqlExecuteScanOptions{ Database: "codeqlDB", } - cmd, err := prepareCmdForDatabaseAnalyze(map[string]string{}, config, "sarif-latest", "target/codeqlReport.sarif") + cmd, err := prepareCmdForDatabaseAnalyze(utils, map[string]string{}, config, "sarif-latest", "target/codeqlReport.sarif") assert.NoError(t, err) assert.NotEmpty(t, cmd) assert.Equal(t, 5, len(cmd)) @@ -422,7 +429,7 @@ func TestPrepareCmdForDatabaseAnalyze(t *testing.T) { config := &codeqlExecuteScanOptions{ Database: "codeqlDB", } - cmd, err := prepareCmdForDatabaseAnalyze(map[string]string{}, config, "csv", "target/codeqlReport.csv") + cmd, err := prepareCmdForDatabaseAnalyze(utils, map[string]string{}, config, "csv", "target/codeqlReport.csv") assert.NoError(t, err) assert.NotEmpty(t, cmd) assert.Equal(t, 5, len(cmd)) @@ -434,7 +441,7 @@ func TestPrepareCmdForDatabaseAnalyze(t *testing.T) { Database: "codeqlDB", QuerySuite: "security.ql", } - cmd, err := prepareCmdForDatabaseAnalyze(map[string]string{}, config, "sarif-latest", "target/codeqlReport.sarif") + cmd, err := prepareCmdForDatabaseAnalyze(utils, map[string]string{}, config, "sarif-latest", "target/codeqlReport.sarif") assert.NoError(t, err) assert.NotEmpty(t, cmd) assert.Equal(t, 6, len(cmd)) @@ -448,7 +455,7 @@ func TestPrepareCmdForDatabaseAnalyze(t *testing.T) { Threads: "1", Ram: "2000", } - cmd, err := prepareCmdForDatabaseAnalyze(map[string]string{}, config, "sarif-latest", "target/codeqlReport.sarif") + cmd, err := prepareCmdForDatabaseAnalyze(utils, map[string]string{}, config, "sarif-latest", "target/codeqlReport.sarif") assert.NoError(t, err) assert.NotEmpty(t, cmd) assert.Equal(t, 8, len(cmd)) @@ -465,7 +472,7 @@ func TestPrepareCmdForDatabaseAnalyze(t *testing.T) { customFlags := map[string]string{ "--threads": "--threads=2", } - cmd, err := prepareCmdForDatabaseAnalyze(customFlags, config, "sarif-latest", "target/codeqlReport.sarif") + cmd, err := prepareCmdForDatabaseAnalyze(utils, customFlags, config, "sarif-latest", "target/codeqlReport.sarif") assert.NoError(t, err) assert.NotEmpty(t, cmd) assert.Equal(t, 8, len(cmd)) @@ -482,7 +489,7 @@ func TestPrepareCmdForDatabaseAnalyze(t *testing.T) { customFlags := map[string]string{ "-j": "-j=2", } - cmd, err := prepareCmdForDatabaseAnalyze(customFlags, config, "sarif-latest", "target/codeqlReport.sarif") + cmd, err := prepareCmdForDatabaseAnalyze(utils, customFlags, config, "sarif-latest", "target/codeqlReport.sarif") assert.NoError(t, err) assert.NotEmpty(t, cmd) assert.Equal(t, 8, len(cmd)) @@ -499,7 +506,7 @@ func TestPrepareCmdForDatabaseAnalyze(t *testing.T) { customFlags := map[string]string{ "--no-download": "--no-download", } - cmd, err := prepareCmdForDatabaseAnalyze(customFlags, config, "sarif-latest", "target/codeqlReport.sarif") + cmd, err := prepareCmdForDatabaseAnalyze(utils, customFlags, config, "sarif-latest", "target/codeqlReport.sarif") assert.NoError(t, err) assert.NotEmpty(t, cmd) assert.Equal(t, 9, len(cmd)) @@ -559,21 +566,54 @@ func TestPrepareCmdForUploadResults(t *testing.T) { }) } -func TestAppendCodeqlQuery(t *testing.T) { +func TestAppendCodeqlQuerySuite(t *testing.T) { t.Parallel() t.Run("Empty query", func(t *testing.T) { + utils := newCodeqlExecuteScanTestsUtils() cmd := []string{"database", "analyze"} - query := "" - cmd = appendCodeqlQuery(cmd, query) + querySuite := "" + cmd = appendCodeqlQuerySuite(utils, cmd, querySuite, "") assert.Equal(t, 2, len(cmd)) }) t.Run("Not empty query", func(t *testing.T) { + utils := newCodeqlExecuteScanTestsUtils() + cmd := []string{"database", "analyze"} + querySuite := "java-extended.ql" + cmd = appendCodeqlQuerySuite(utils, cmd, querySuite, "") + assert.Equal(t, 3, len(cmd)) + }) + + t.Run("Add prefix to querySuite", func(t *testing.T) { + utils := codeqlExecuteScanMockUtils{ + ExecMockRunner: &mock.ExecMockRunner{ + Stub: func(call string, stdoutReturn map[string]string, shouldFailOnCommand map[string]error, stdout io.Writer) error { + stdout.Write([]byte("test-java-security-extended.qls")) + return nil + }, + }, + } + cmd := []string{"database", "analyze"} + querySuite := "java-security-extended.qls" + cmd = appendCodeqlQuerySuite(utils, cmd, querySuite, `s/^(java|python)-(security-extended\.qls|security-and-quality\.qls)/test-\1-\2/`) + assert.Equal(t, 3, len(cmd)) + assert.Equal(t, "test-java-security-extended.qls", cmd[2]) + }) + + t.Run("Don't add prefix to querySuite", func(t *testing.T) { + utils := codeqlExecuteScanMockUtils{ + ExecMockRunner: &mock.ExecMockRunner{ + Stub: func(call string, stdoutReturn map[string]string, shouldFailOnCommand map[string]error, stdout io.Writer) error { + return fmt.Errorf("error") + }, + }, + } cmd := []string{"database", "analyze"} - query := "java-extended.ql" - cmd = appendCodeqlQuery(cmd, query) + querySuite := "php-security-extended.qls" + cmd = appendCodeqlQuerySuite(utils, cmd, querySuite, `s/^(java|python)-(security-extended\.qls|security-and-quality\.qls)/test-\1-\2/`) assert.Equal(t, 3, len(cmd)) + assert.Equal(t, "php-security-extended.qls", cmd[2]) }) } diff --git a/resources/metadata/codeqlExecuteScan.yaml b/resources/metadata/codeqlExecuteScan.yaml index eb9c5d9374..a35952d976 100644 --- a/resources/metadata/codeqlExecuteScan.yaml +++ b/resources/metadata/codeqlExecuteScan.yaml @@ -240,6 +240,13 @@ spec: - STEPS - STAGES - PARAMETERS + - name: transformQuerySuite + type: string + description: "A transform string that will be applied to the querySuite using the sed command." + scope: + - STEPS + - STAGES + - PARAMETERS containers: - image: "" outputs: From 8eeba2d0055a7c645a60de0466d1ed21194b0c70 Mon Sep 17 00:00:00 2001 From: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> Date: Mon, 10 Jun 2024 10:51:22 +0200 Subject: [PATCH 5/5] [ABAP] Migrate SAP_COM_0510 to SAP_COM_0948 (#4925) * Migrate SAP_COM_0510 to SAP_COM_0948 * Update error message * Update error message * Fix error message in unit test * Update unit tests --- cmd/abapEnvironmentCheckoutBranch_generated.go | 8 ++++---- cmd/abapEnvironmentCloneGitRepo_generated.go | 8 ++++---- cmd/abapEnvironmentCreateTag_generated.go | 8 ++++---- cmd/abapEnvironmentPullGitRepo_generated.go | 8 ++++---- cmd/abapEnvironmentRunATCCheck_test.go | 4 ++-- .../docs/pipelines/abapEnvironment/stages/build.md | 2 +- .../pipelines/abapEnvironment/stages/cloneRepositories.md | 2 +- documentation/docs/steps/abapEnvironmentCheckoutBranch.md | 2 +- documentation/docs/steps/abapEnvironmentCloneGitRepo.md | 2 +- documentation/docs/steps/abapEnvironmentCreateTag.md | 2 +- documentation/docs/steps/abapEnvironmentPullGitRepo.md | 2 +- pkg/abaputils/abaputils.go | 2 +- pkg/abaputils/abaputils_test.go | 2 +- .../pipeline/abapEnvironmentPipelineDefaults.yml | 5 ++--- resources/metadata/abapEnvironmentCheckoutBranch.yaml | 8 ++++---- resources/metadata/abapEnvironmentCloneGitRepo.yaml | 8 ++++---- resources/metadata/abapEnvironmentCreateTag.yaml | 8 ++++---- resources/metadata/abapEnvironmentPullGitRepo.yaml | 8 ++++---- 18 files changed, 44 insertions(+), 45 deletions(-) diff --git a/cmd/abapEnvironmentCheckoutBranch_generated.go b/cmd/abapEnvironmentCheckoutBranch_generated.go index 4939e41a0a..988ebfc9d4 100644 --- a/cmd/abapEnvironmentCheckoutBranch_generated.go +++ b/cmd/abapEnvironmentCheckoutBranch_generated.go @@ -47,8 +47,8 @@ func AbapEnvironmentCheckoutBranchCommand() *cobra.Command { Long: `This step switches between branches of a git repository (Software Component) on a SAP BTP ABAP Environment system. Please provide either of the following options: -* The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). -* The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. +* The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0948](https://help.sap.com/docs/sap-btp-abap-environment/abap-environment/api-for-managing-software-components-61f4d47af1394b1c8ad684b71d3ad6a0?locale=en-US). +* The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0948. * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority.`, PreRunE: func(cmd *cobra.Command, _ []string) error { startTime = time.Now() @@ -136,8 +136,8 @@ Please provide either of the following options: } func addAbapEnvironmentCheckoutBranchFlags(cmd *cobra.Command, stepConfig *abapEnvironmentCheckoutBranchOptions) { - cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") - cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") + cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948") + cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948") cmd.Flags().StringVar(&stepConfig.RepositoryName, "repositoryName", os.Getenv("PIPER_repositoryName"), "Specifies a Repository (Software Component) on the SAP BTP ABAP Environment system") cmd.Flags().StringVar(&stepConfig.BranchName, "branchName", os.Getenv("PIPER_branchName"), "Specifies a Branch of a Repository (Software Component) on the SAP BTP ABAP Environment system") cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Specifies the host address of the SAP BTP ABAP Environment system") diff --git a/cmd/abapEnvironmentCloneGitRepo_generated.go b/cmd/abapEnvironmentCloneGitRepo_generated.go index 8f37662939..9cba6305e5 100644 --- a/cmd/abapEnvironmentCloneGitRepo_generated.go +++ b/cmd/abapEnvironmentCloneGitRepo_generated.go @@ -47,8 +47,8 @@ func AbapEnvironmentCloneGitRepoCommand() *cobra.Command { Long: `Clones a git repository (Software Component) to a SAP BTP ABAP Environment system. If the repository is already cloned, the step will checkout the configured branch and pull the specified commit, instead. Please provide either of the following options: -* The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). -* The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. +* The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0948](https://help.sap.com/docs/sap-btp-abap-environment/abap-environment/api-for-managing-software-components-61f4d47af1394b1c8ad684b71d3ad6a0?locale=en-US). +* The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0948. * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority.`, PreRunE: func(cmd *cobra.Command, _ []string) error { startTime = time.Now() @@ -136,8 +136,8 @@ Please provide either of the following options: } func addAbapEnvironmentCloneGitRepoFlags(cmd *cobra.Command, stepConfig *abapEnvironmentCloneGitRepoOptions) { - cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") - cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") + cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948") + cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948") cmd.Flags().StringVar(&stepConfig.Repositories, "repositories", os.Getenv("PIPER_repositories"), "Specifies a YAML file containing the repositories configuration") cmd.Flags().StringVar(&stepConfig.RepositoryName, "repositoryName", os.Getenv("PIPER_repositoryName"), "Specifies a repository (Software Components) on the SAP BTP ABAP Environment system") cmd.Flags().StringVar(&stepConfig.BranchName, "branchName", os.Getenv("PIPER_branchName"), "Specifies a branch of a repository (Software Components) on the SAP BTP ABAP Environment system") diff --git a/cmd/abapEnvironmentCreateTag_generated.go b/cmd/abapEnvironmentCreateTag_generated.go index 86886f8a72..02b47ef577 100644 --- a/cmd/abapEnvironmentCreateTag_generated.go +++ b/cmd/abapEnvironmentCreateTag_generated.go @@ -51,8 +51,8 @@ func AbapEnvironmentCreateTagCommand() *cobra.Command { Long: `Creates tags for specific commits of one or multiple repositories / software components. The tag can be specified explicitly as well as being generated by an addon product version or an addon component version. Please provide either of the following options: -* The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). -* The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. +* The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0948](https://help.sap.com/docs/sap-btp-abap-environment/abap-environment/api-for-managing-software-components-61f4d47af1394b1c8ad684b71d3ad6a0?locale=en-US). +* The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0948. * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority.`, PreRunE: func(cmd *cobra.Command, _ []string) error { startTime = time.Now() @@ -140,8 +140,8 @@ Please provide either of the following options: } func addAbapEnvironmentCreateTagFlags(cmd *cobra.Command, stepConfig *abapEnvironmentCreateTagOptions) { - cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") - cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") + cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948") + cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948") cmd.Flags().StringVar(&stepConfig.Repositories, "repositories", os.Getenv("PIPER_repositories"), "Specifies a YAML file containing the repositories configuration") cmd.Flags().StringVar(&stepConfig.RepositoryName, "repositoryName", os.Getenv("PIPER_repositoryName"), "Specifies a repository (Software Components) on the SAP BTP ABAP Environment system") cmd.Flags().StringVar(&stepConfig.CommitID, "commitID", os.Getenv("PIPER_commitID"), "Specifies a commitID, for which a tag will be created") diff --git a/cmd/abapEnvironmentPullGitRepo_generated.go b/cmd/abapEnvironmentPullGitRepo_generated.go index 547deaec7a..3575ef4fb2 100644 --- a/cmd/abapEnvironmentPullGitRepo_generated.go +++ b/cmd/abapEnvironmentPullGitRepo_generated.go @@ -49,8 +49,8 @@ func AbapEnvironmentPullGitRepoCommand() *cobra.Command { Long: `Pulls a git repository (Software Component) to a SAP BTP ABAP Environment system. Please provide either of the following options: -* The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). -* The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. +* The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0948](https://help.sap.com/docs/sap-btp-abap-environment/abap-environment/api-for-managing-software-components-61f4d47af1394b1c8ad684b71d3ad6a0?locale=en-US). +* The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0948. * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority.`, PreRunE: func(cmd *cobra.Command, _ []string) error { startTime = time.Now() @@ -138,8 +138,8 @@ Please provide either of the following options: } func addAbapEnvironmentPullGitRepoFlags(cmd *cobra.Command, stepConfig *abapEnvironmentPullGitRepoOptions) { - cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") - cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") + cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948") + cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948") cmd.Flags().StringSliceVar(&stepConfig.RepositoryNames, "repositoryNames", []string{}, "Specifies a list of Repositories (Software Components) on the SAP BTP ABAP Environment system") cmd.Flags().StringVar(&stepConfig.Repositories, "repositories", os.Getenv("PIPER_repositories"), "Specifies a YAML file containing the repositories configuration") cmd.Flags().StringVar(&stepConfig.RepositoryName, "repositoryName", os.Getenv("PIPER_repositoryName"), "Specifies a repository (Software Component) on the SAP BTP ABAP Environment system") diff --git a/cmd/abapEnvironmentRunATCCheck_test.go b/cmd/abapEnvironmentRunATCCheck_test.go index c39f64524c..ea607c5f32 100644 --- a/cmd/abapEnvironmentRunATCCheck_test.go +++ b/cmd/abapEnvironmentRunATCCheck_test.go @@ -58,10 +58,10 @@ func TestHostConfig(t *testing.T) { } _, err := autils.GetAbapCommunicationArrangementInfo(options.AbapEnvOptions, "") - assert.EqualError(t, err, "Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry ApiEndpoint, Organization, Space, Service Instance and a corresponding Service Key for the Communication Scenario SAP_COM_0510") + assert.EqualError(t, err, "Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry API Endpoint, Organization, Space, Service Instance and Service Key") _, err = autils.GetAbapCommunicationArrangementInfo(options.AbapEnvOptions, "") - assert.EqualError(t, err, "Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry ApiEndpoint, Organization, Space, Service Instance and a corresponding Service Key for the Communication Scenario SAP_COM_0510") + assert.EqualError(t, err, "Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry API Endpoint, Organization, Space, Service Instance and Service Key") }) t.Run("Check Host: CF Service Key", func(t *testing.T) { diff --git a/documentation/docs/pipelines/abapEnvironment/stages/build.md b/documentation/docs/pipelines/abapEnvironment/stages/build.md index b818efa2d4..8665598fac 100644 --- a/documentation/docs/pipelines/abapEnvironment/stages/build.md +++ b/documentation/docs/pipelines/abapEnvironment/stages/build.md @@ -35,7 +35,7 @@ general: cfSpace: 'mySpaceBld' cfCredentialsId: 'cfAuthentification' cfServiceInstance: 'bld_system' - cfServiceKeyName: 'JENKINS_SAP_COM_0510' + cfServiceKeyName: 'JENKINS_SAP_COM_0948' stages: Build: cfServiceKeyName: 'JENKINS_SAP_COM_0582' diff --git a/documentation/docs/pipelines/abapEnvironment/stages/cloneRepositories.md b/documentation/docs/pipelines/abapEnvironment/stages/cloneRepositories.md index b7fc250b1b..791edd29af 100644 --- a/documentation/docs/pipelines/abapEnvironment/stages/cloneRepositories.md +++ b/documentation/docs/pipelines/abapEnvironment/stages/cloneRepositories.md @@ -1,6 +1,6 @@ # Clone Repositories -This stage creates pulls/clones the specified software components (repositories) to the SAP BTP, ABAP environment system. As a prerequisite, the Communication Arrangement [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html) (SAP BTP, ABAP Environment - Software Component Test Integration) is created using the step `cloudFoundryCreateServiceKey`. With the creation of the Communication Arrangement, a User and Password is created on the SAP BTP, ABAP environment system for the APIs that are used in this stage, as well as in the ATC stage. +This stage creates pulls/clones the specified software components (repositories) to the SAP BTP, ABAP environment system. As a prerequisite, the Communication Arrangement [SAP_COM_0948](https://help.sap.com/docs/ABAP_ENVIRONMENT/250515df61b74848810389e964f8c367/61f4d47af1394b1c8ad684b71d3ad6a0.html?locale=en-US) (Software Component Management Integration) is created using the step `cloudFoundryCreateServiceKey`. With the creation of the Communication Arrangement, a User and Password is created on the SAP BTP, ABAP environment system for the APIs that are used in this stage, as well as in the ATC stage. ## Steps diff --git a/documentation/docs/steps/abapEnvironmentCheckoutBranch.md b/documentation/docs/steps/abapEnvironmentCheckoutBranch.md index 3aeb70cd7b..282631ad27 100644 --- a/documentation/docs/steps/abapEnvironmentCheckoutBranch.md +++ b/documentation/docs/steps/abapEnvironmentCheckoutBranch.md @@ -5,7 +5,7 @@ ## Prerequisites A SAP BTP, ABAP environment system is available. -On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "SAP BTP, ABAP Environment - Software Component Test Integration (SAP_COM_0510)". This can be done manually through the respective applications on the SAP BTP, ABAP environment system or through creating a service key for the system on Cloud Foundry with the parameters {"scenario_id": "SAP_COM_0510", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). In addition, the software component should be cloned into the system instance. You can do this with the step [abapEnvironmentCloneGitRepo](./abapEnvironmentCloneGitRepo.md). +On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "Software Component Management Integration (SAP_COM_0948)". This can be done manually through the respective applications on the SAP BTP, ABAP environment system or through creating a service key for the system on Cloud Foundry with the parameters {"scenario_id": "SAP_COM_0948", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). In addition, the software component should be cloned into the system instance. You can do this with the step [abapEnvironmentCloneGitRepo](./abapEnvironmentCloneGitRepo.md). ## ${docGenParameters} diff --git a/documentation/docs/steps/abapEnvironmentCloneGitRepo.md b/documentation/docs/steps/abapEnvironmentCloneGitRepo.md index 6a81ac063e..8bdf906a74 100644 --- a/documentation/docs/steps/abapEnvironmentCloneGitRepo.md +++ b/documentation/docs/steps/abapEnvironmentCloneGitRepo.md @@ -5,7 +5,7 @@ ## Prerequisites A SAP BTP, ABAP environment system is available. -On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "SAP BTP, ABAP Environment - Software Component Test Integration (SAP_COM_0510)". This can be done manually through the respective applications on the SAP BTP, ABAP environment system or through creating a service key for the system on Cloud Foundry with the parameters {"scenario_id": "SAP_COM_0510", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). +On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "Software Component Management Integration (SAP_COM_0948)". This can be done manually through the respective applications on the SAP BTP, ABAP environment system or through creating a service key for the system on Cloud Foundry with the parameters {"scenario_id": "SAP_COM_0948", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). ## ${docGenParameters} diff --git a/documentation/docs/steps/abapEnvironmentCreateTag.md b/documentation/docs/steps/abapEnvironmentCreateTag.md index 08f8312ffd..3a44efbb1a 100644 --- a/documentation/docs/steps/abapEnvironmentCreateTag.md +++ b/documentation/docs/steps/abapEnvironmentCreateTag.md @@ -5,7 +5,7 @@ ## Prerequisites A SAP BTP, ABAP environment system is available. -On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "SAP BTP, ABAP Environment - Software Component Test Integration (SAP_COM_0510)". This can be done manually through the respective applications on the SAP BTP, ABAP environment system or through creating a service key for the system on Cloud Foundry with the parameters {"scenario_id": "SAP_COM_0510", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). In addition, the software component should be cloned into the system instance. You can do this with the step [abapEnvironmentCloneGitRepo](./abapEnvironmentCloneGitRepo.md). +On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "Software Component Management Integration (SAP_COM_0948)". This can be done manually through the respective applications on the SAP BTP, ABAP environment system or through creating a service key for the system on Cloud Foundry with the parameters {"scenario_id": "SAP_COM_0948", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). In addition, the software component should be cloned into the system instance. You can do this with the step [abapEnvironmentCloneGitRepo](./abapEnvironmentCloneGitRepo.md). ## ${docGenParameters} diff --git a/documentation/docs/steps/abapEnvironmentPullGitRepo.md b/documentation/docs/steps/abapEnvironmentPullGitRepo.md index 7b727a332c..2d3f9ef6e0 100644 --- a/documentation/docs/steps/abapEnvironmentPullGitRepo.md +++ b/documentation/docs/steps/abapEnvironmentPullGitRepo.md @@ -5,7 +5,7 @@ ## Prerequisites A SAP BTP, ABAP environment system is available. -On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "SAP BTP, ABAP Environment - Software Component Test Integration (SAP_COM_0510)". This can be done manually through the respective applications on the SAP BTP, ABAP environment system or through creating a service key for the system on Cloud Foundry with the parameters {"scenario_id": "SAP_COM_0510", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). In addition, the software component should be cloned into the system instance. You can do this with the step [abapEnvironmentCloneGitRepo](./abapEnvironmentCloneGitRepo.md). +On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "Software Component Management Integration (SAP_COM_0948)". This can be done manually through the respective applications on the SAP BTP, ABAP environment system or through creating a service key for the system on Cloud Foundry with the parameters {"scenario_id": "SAP_COM_0948", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). In addition, the software component should be cloned into the system instance. You can do this with the step [abapEnvironmentCloneGitRepo](./abapEnvironmentCloneGitRepo.md). ## ${docGenParameters} diff --git a/pkg/abaputils/abaputils.go b/pkg/abaputils/abaputils.go index 6f3d20bf35..caf6cb9938 100644 --- a/pkg/abaputils/abaputils.go +++ b/pkg/abaputils/abaputils.go @@ -59,7 +59,7 @@ func (abaputils *AbapUtils) GetAbapCommunicationArrangementInfo(options AbapEnvi connectionDetails.Password = options.Password } else { if options.CfAPIEndpoint == "" || options.CfOrg == "" || options.CfSpace == "" || options.CfServiceInstance == "" || options.CfServiceKeyName == "" { - var err = errors.New("Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry ApiEndpoint, Organization, Space, Service Instance and a corresponding Service Key for the Communication Scenario SAP_COM_0510") + var err = errors.New("Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry API Endpoint, Organization, Space, Service Instance and Service Key") log.SetErrorCategory(log.ErrorConfiguration) return connectionDetails, err } diff --git a/pkg/abaputils/abaputils_test.go b/pkg/abaputils/abaputils_test.go index 56688f7aec..d9b0cafa2d 100644 --- a/pkg/abaputils/abaputils_test.go +++ b/pkg/abaputils/abaputils_test.go @@ -45,7 +45,7 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) { assert.Equal(t, "", connectionDetails.Password) assert.Equal(t, "", connectionDetails.XCsrfToken) - assert.EqualError(t, err, "Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry ApiEndpoint, Organization, Space, Service Instance and a corresponding Service Key for the Communication Scenario SAP_COM_0510") + assert.EqualError(t, err, "Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry API Endpoint, Organization, Space, Service Instance and Service Key") }) t.Run("CF GetAbapCommunicationArrangementInfo - Error - reading service Key", func(t *testing.T) { //given diff --git a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineDefaults.yml b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineDefaults.yml index 79d294985a..dee60fe06a 100644 --- a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineDefaults.yml +++ b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineDefaults.yml @@ -12,12 +12,11 @@ stages: abapSystemIsDevelopmentAllowed: 'false' abapSystemSizeOfPersistence: 2 abapSystemSizeOfRuntime: 1 - cfServiceKeyName: 'sap_com_0510' cfAsync: false 'Clone Repositories': - cfServiceKeyName: 'sap_com_0510' - cfServiceKeyConfig: '{"scenario_id":"SAP_COM_0510","type":"basic"}' + cfServiceKeyName: 'sap_com_0948' + cfServiceKeyConfig: '{"scenario_id":"SAP_COM_0948","type":"basic"}' cfAsync: false ordinal: 30 diff --git a/resources/metadata/abapEnvironmentCheckoutBranch.yaml b/resources/metadata/abapEnvironmentCheckoutBranch.yaml index 65f0aeb8b6..37d2729b76 100644 --- a/resources/metadata/abapEnvironmentCheckoutBranch.yaml +++ b/resources/metadata/abapEnvironmentCheckoutBranch.yaml @@ -5,8 +5,8 @@ metadata: This step switches between branches of a git repository (Software Component) on a SAP BTP ABAP Environment system. Please provide either of the following options: - * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). - * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. + * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0948](https://help.sap.com/docs/sap-btp-abap-environment/abap-environment/api-for-managing-software-components-61f4d47af1394b1c8ad684b71d3ad6a0?locale=en-US). + * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0948. * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority. spec: @@ -21,7 +21,7 @@ spec: params: - name: username type: string - description: User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510 + description: User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948 scope: - PARAMETERS - STAGES @@ -34,7 +34,7 @@ spec: param: username - name: password type: string - description: Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510 + description: Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948 scope: - PARAMETERS - STAGES diff --git a/resources/metadata/abapEnvironmentCloneGitRepo.yaml b/resources/metadata/abapEnvironmentCloneGitRepo.yaml index e4d4035cf0..e3d3828388 100644 --- a/resources/metadata/abapEnvironmentCloneGitRepo.yaml +++ b/resources/metadata/abapEnvironmentCloneGitRepo.yaml @@ -5,8 +5,8 @@ metadata: Clones a git repository (Software Component) to a SAP BTP ABAP Environment system. If the repository is already cloned, the step will checkout the configured branch and pull the specified commit, instead. Please provide either of the following options: - * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). - * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. + * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0948](https://help.sap.com/docs/sap-btp-abap-environment/abap-environment/api-for-managing-software-components-61f4d47af1394b1c8ad684b71d3ad6a0?locale=en-US). + * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0948. * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority. spec: @@ -21,7 +21,7 @@ spec: params: - name: username type: string - description: User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510 + description: User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948 scope: - PARAMETERS - STAGES @@ -34,7 +34,7 @@ spec: param: username - name: password type: string - description: Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510 + description: Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948 scope: - PARAMETERS - STAGES diff --git a/resources/metadata/abapEnvironmentCreateTag.yaml b/resources/metadata/abapEnvironmentCreateTag.yaml index 58403f3add..947db9d7f2 100644 --- a/resources/metadata/abapEnvironmentCreateTag.yaml +++ b/resources/metadata/abapEnvironmentCreateTag.yaml @@ -5,8 +5,8 @@ metadata: Creates tags for specific commits of one or multiple repositories / software components. The tag can be specified explicitly as well as being generated by an addon product version or an addon component version. Please provide either of the following options: - * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). - * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. + * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0948](https://help.sap.com/docs/sap-btp-abap-environment/abap-environment/api-for-managing-software-components-61f4d47af1394b1c8ad684b71d3ad6a0?locale=en-US). + * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0948. * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority. spec: @@ -21,7 +21,7 @@ spec: params: - name: username type: string - description: User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510 + description: User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948 scope: - PARAMETERS - STAGES @@ -34,7 +34,7 @@ spec: param: username - name: password type: string - description: Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510 + description: Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948 scope: - PARAMETERS - STAGES diff --git a/resources/metadata/abapEnvironmentPullGitRepo.yaml b/resources/metadata/abapEnvironmentPullGitRepo.yaml index 576a4e7652..ba3da2f3e9 100644 --- a/resources/metadata/abapEnvironmentPullGitRepo.yaml +++ b/resources/metadata/abapEnvironmentPullGitRepo.yaml @@ -5,8 +5,8 @@ metadata: Pulls a git repository (Software Component) to a SAP BTP ABAP Environment system. Please provide either of the following options: - * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). - * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. + * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0948](https://help.sap.com/docs/sap-btp-abap-environment/abap-environment/api-for-managing-software-components-61f4d47af1394b1c8ad684b71d3ad6a0?locale=en-US). + * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0948. * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority. spec: @@ -21,7 +21,7 @@ spec: params: - name: username type: string - description: User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510 + description: User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948 scope: - PARAMETERS - STAGES @@ -34,7 +34,7 @@ spec: param: username - name: password type: string - description: Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510 + description: Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0948 scope: - PARAMETERS - STAGES