From 48b636e32b1e0c38cab7270ccac244197f960512 Mon Sep 17 00:00:00 2001 From: pasha-codefresh Date: Wed, 17 Apr 2024 00:33:47 +0300 Subject: [PATCH] chore: native client mock should be generated with go gen (#17864) * fix: native client mock should be generated with go gen Signed-off-by: pashakostohrys * fix: native client mock should be generated with go gen Signed-off-by: pashakostohrys * fix: native client mock should be generated with go gen Signed-off-by: pashakostohrys * adopt repository_test.go to new helm mock client Signed-off-by: pashakostohrys --------- Signed-off-by: pashakostohrys --- reposerver/repository/repository_test.go | 4 +- util/helm/client.go | 2 + util/helm/mocks/Client.go | 69 ++++++++++++++++-------- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/reposerver/repository/repository_test.go b/reposerver/repository/repository_test.go index 9487a0c97355b..34b8088c77d12 100644 --- a/reposerver/repository/repository_test.go +++ b/reposerver/repository/repository_test.go @@ -123,8 +123,8 @@ func newServiceWithMocks(t *testing.T, root string, signed bool) (*Service, *git chart: {{Version: "1.0.0"}, {Version: version}}, oobChart: {{Version: "1.0.0"}, {Version: version}}, }}, nil) - helmClient.On("ExtractChart", chart, version).Return("./testdata/my-chart", io.NopCloser, nil) - helmClient.On("ExtractChart", oobChart, version).Return("./testdata2/out-of-bounds-chart", io.NopCloser, nil) + helmClient.On("ExtractChart", chart, version, false, int64(0), false).Return("./testdata/my-chart", io.NopCloser, nil) + helmClient.On("ExtractChart", oobChart, version, false, int64(0), false).Return("./testdata2/out-of-bounds-chart", io.NopCloser, nil) helmClient.On("CleanChartCache", chart, version).Return(nil) helmClient.On("CleanChartCache", oobChart, version).Return(nil) helmClient.On("DependencyBuild").Return(nil) diff --git a/util/helm/client.go b/util/helm/client.go index 8b99cd67c6904..aab627cb7c4fb 100644 --- a/util/helm/client.go +++ b/util/helm/client.go @@ -32,6 +32,8 @@ import ( "github.com/argoproj/argo-cd/v2/util/proxy" ) +//go:generate go run github.com/vektra/mockery/v2@v2.25.1 --name=Client + var ( globalLock = sync.NewKeyLock() indexLock = sync.NewKeyLock() diff --git a/util/helm/mocks/Client.go b/util/helm/mocks/Client.go index 0acae845a3d33..a950d953b05a4 100644 --- a/util/helm/mocks/Client.go +++ b/util/helm/mocks/Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.25.1. DO NOT EDIT. package mocks @@ -28,29 +28,32 @@ func (_m *Client) CleanChartCache(chart string, version string) error { return r0 } -// ExtractChart provides a mock function with given fields: chart, version +// ExtractChart provides a mock function with given fields: chart, version, passCredentials, manifestMaxExtractedSize, disableManifestMaxExtractedSize func (_m *Client) ExtractChart(chart string, version string, passCredentials bool, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) (string, io.Closer, error) { - ret := _m.Called(chart, version) + ret := _m.Called(chart, version, passCredentials, manifestMaxExtractedSize, disableManifestMaxExtractedSize) var r0 string - if rf, ok := ret.Get(0).(func(string, string) string); ok { - r0 = rf(chart, version) + var r1 io.Closer + var r2 error + if rf, ok := ret.Get(0).(func(string, string, bool, int64, bool) (string, io.Closer, error)); ok { + return rf(chart, version, passCredentials, manifestMaxExtractedSize, disableManifestMaxExtractedSize) + } + if rf, ok := ret.Get(0).(func(string, string, bool, int64, bool) string); ok { + r0 = rf(chart, version, passCredentials, manifestMaxExtractedSize, disableManifestMaxExtractedSize) } else { r0 = ret.Get(0).(string) } - var r1 io.Closer - if rf, ok := ret.Get(1).(func(string, string) io.Closer); ok { - r1 = rf(chart, version) + if rf, ok := ret.Get(1).(func(string, string, bool, int64, bool) io.Closer); ok { + r1 = rf(chart, version, passCredentials, manifestMaxExtractedSize, disableManifestMaxExtractedSize) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(io.Closer) } } - var r2 error - if rf, ok := ret.Get(2).(func(string, string) error); ok { - r2 = rf(chart, version) + if rf, ok := ret.Get(2).(func(string, string, bool, int64, bool) error); ok { + r2 = rf(chart, version, passCredentials, manifestMaxExtractedSize, disableManifestMaxExtractedSize) } else { r2 = ret.Error(2) } @@ -58,22 +61,25 @@ func (_m *Client) ExtractChart(chart string, version string, passCredentials boo return r0, r1, r2 } -// GetIndex provides a mock function with given fields: noCache +// GetIndex provides a mock function with given fields: noCache, maxIndexSize func (_m *Client) GetIndex(noCache bool, maxIndexSize int64) (*helm.Index, error) { - ret := _m.Called(noCache) + ret := _m.Called(noCache, maxIndexSize) var r0 *helm.Index - if rf, ok := ret.Get(0).(func(bool) *helm.Index); ok { - r0 = rf(noCache) + var r1 error + if rf, ok := ret.Get(0).(func(bool, int64) (*helm.Index, error)); ok { + return rf(noCache, maxIndexSize) + } + if rf, ok := ret.Get(0).(func(bool, int64) *helm.Index); ok { + r0 = rf(noCache, maxIndexSize) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*helm.Index) } } - var r1 error - if rf, ok := ret.Get(1).(func(bool) error); ok { - r1 = rf(noCache) + if rf, ok := ret.Get(1).(func(bool, int64) error); ok { + r1 = rf(noCache, maxIndexSize) } else { r1 = ret.Error(1) } @@ -81,11 +87,15 @@ func (_m *Client) GetIndex(noCache bool, maxIndexSize int64) (*helm.Index, error return r0, r1 } -// GetTags provides a mock function with given fields: noCache +// GetTags provides a mock function with given fields: chart, noCache func (_m *Client) GetTags(chart string, noCache bool) (*helm.TagsList, error) { ret := _m.Called(chart, noCache) var r0 *helm.TagsList + var r1 error + if rf, ok := ret.Get(0).(func(string, bool) (*helm.TagsList, error)); ok { + return rf(chart, noCache) + } if rf, ok := ret.Get(0).(func(string, bool) *helm.TagsList); ok { r0 = rf(chart, noCache) } else { @@ -94,7 +104,6 @@ func (_m *Client) GetTags(chart string, noCache bool) (*helm.TagsList, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string, bool) error); ok { r1 = rf(chart, noCache) } else { @@ -109,13 +118,16 @@ func (_m *Client) TestHelmOCI() (bool, error) { ret := _m.Called() var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func() (bool, error)); ok { + return rf() + } if rf, ok := ret.Get(0).(func() bool); ok { r0 = rf() } else { r0 = ret.Get(0).(bool) } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -124,3 +136,18 @@ func (_m *Client) TestHelmOCI() (bool, error) { return r0, r1 } + +type mockConstructorTestingTNewClient interface { + mock.TestingT + Cleanup(func()) +} + +// NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewClient(t mockConstructorTestingTNewClient) *Client { + mock := &Client{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}