From a4441ee6f8946db654c548914ef1dbcb5b7d334a Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Mon, 23 Oct 2023 18:53:46 +0200 Subject: [PATCH] GO-2246 fix tests --- Makefile | 2 +- .../objectstore/indexer_store_test.go | 4 +- .../mock_objectstore/mock_ObjectStore.go | 97 ++++++++++++++++--- util/testMock/objectstore_mock.go | 27 +++++- 4 files changed, 107 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index f9b7e189c..c9c1bf8d6 100644 --- a/Makefile +++ b/Makefile @@ -73,7 +73,7 @@ test-deps: @go build -o deps go.uber.org/mock/mockgen @go build -o deps github.com/vektra/mockery/v2 @go generate ./... - @mockery --all + @$(DEPS_PATH)/mockery --all clear-test-deps: @echo 'Removing test mocks...' diff --git a/pkg/lib/localstore/objectstore/indexer_store_test.go b/pkg/lib/localstore/objectstore/indexer_store_test.go index 0793dad7b..b7b641c03 100644 --- a/pkg/lib/localstore/objectstore/indexer_store_test.go +++ b/pkg/lib/localstore/objectstore/indexer_store_test.go @@ -56,9 +56,9 @@ func TestIndexerChecksums(t *testing.T) { FilestoreKeysForceReindexCounter: 6, } - require.NoError(t, s.SaveGlobalChecksums(want)) + require.NoError(t, s.SaveChecksums("spaceX", want)) - got, err := s.GetGlobalChecksums() + got, err := s.GetChecksums("spaceX") require.NoError(t, err) assert.Equal(t, want, got) }) diff --git a/pkg/lib/localstore/objectstore/mock_objectstore/mock_ObjectStore.go b/pkg/lib/localstore/objectstore/mock_objectstore/mock_ObjectStore.go index ce7a26337..7bca68425 100644 --- a/pkg/lib/localstore/objectstore/mock_objectstore/mock_ObjectStore.go +++ b/pkg/lib/localstore/objectstore/mock_objectstore/mock_ObjectStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.26.1. DO NOT EDIT. +// Code generated by mockery v2.35.2. DO NOT EDIT. package mock_objectstore @@ -124,12 +124,18 @@ func (_c *MockObjectStore_Close_Call) RunAndReturn(run func(context.Context) err } // DeleteDetails provides a mock function with given fields: id -func (_m *MockObjectStore) DeleteDetails(id string) error { - ret := _m.Called(id) +func (_m *MockObjectStore) DeleteDetails(id ...string) error { + _va := make([]interface{}, len(id)) + for _i := range id { + _va[_i] = id[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { - r0 = rf(id) + if rf, ok := ret.Get(0).(func(...string) error); ok { + r0 = rf(id...) } else { r0 = ret.Error(0) } @@ -143,14 +149,21 @@ type MockObjectStore_DeleteDetails_Call struct { } // DeleteDetails is a helper method to define mock.On call -// - id string -func (_e *MockObjectStore_Expecter) DeleteDetails(id interface{}) *MockObjectStore_DeleteDetails_Call { - return &MockObjectStore_DeleteDetails_Call{Call: _e.mock.On("DeleteDetails", id)} +// - id ...string +func (_e *MockObjectStore_Expecter) DeleteDetails(id ...interface{}) *MockObjectStore_DeleteDetails_Call { + return &MockObjectStore_DeleteDetails_Call{Call: _e.mock.On("DeleteDetails", + append([]interface{}{}, id...)...)} } -func (_c *MockObjectStore_DeleteDetails_Call) Run(run func(id string)) *MockObjectStore_DeleteDetails_Call { +func (_c *MockObjectStore_DeleteDetails_Call) Run(run func(id ...string)) *MockObjectStore_DeleteDetails_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + variadicArgs := make([]string, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(string) + } + } + run(variadicArgs...) }) return _c } @@ -160,7 +173,7 @@ func (_c *MockObjectStore_DeleteDetails_Call) Return(_a0 error) *MockObjectStore return _c } -func (_c *MockObjectStore_DeleteDetails_Call) RunAndReturn(run func(string) error) *MockObjectStore_DeleteDetails_Call { +func (_c *MockObjectStore_DeleteDetails_Call) RunAndReturn(run func(...string) error) *MockObjectStore_DeleteDetails_Call { _c.Call.Return(run) return _c } @@ -687,6 +700,59 @@ func (_c *MockObjectStore_GetDetails_Call) RunAndReturn(run func(string) (*model return _c } +// GetGlobalChecksums provides a mock function with given fields: +func (_m *MockObjectStore) GetGlobalChecksums() (*model.ObjectStoreChecksums, error) { + ret := _m.Called() + + var r0 *model.ObjectStoreChecksums + var r1 error + if rf, ok := ret.Get(0).(func() (*model.ObjectStoreChecksums, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.ObjectStoreChecksums); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ObjectStoreChecksums) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockObjectStore_GetGlobalChecksums_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetGlobalChecksums' +type MockObjectStore_GetGlobalChecksums_Call struct { + *mock.Call +} + +// GetGlobalChecksums is a helper method to define mock.On call +func (_e *MockObjectStore_Expecter) GetGlobalChecksums() *MockObjectStore_GetGlobalChecksums_Call { + return &MockObjectStore_GetGlobalChecksums_Call{Call: _e.mock.On("GetGlobalChecksums")} +} + +func (_c *MockObjectStore_GetGlobalChecksums_Call) Run(run func()) *MockObjectStore_GetGlobalChecksums_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockObjectStore_GetGlobalChecksums_Call) Return(checksums *model.ObjectStoreChecksums, err error) *MockObjectStore_GetGlobalChecksums_Call { + _c.Call.Return(checksums, err) + return _c +} + +func (_c *MockObjectStore_GetGlobalChecksums_Call) RunAndReturn(run func() (*model.ObjectStoreChecksums, error)) *MockObjectStore_GetGlobalChecksums_Call { + _c.Call.Return(run) + return _c +} + // GetInboundLinksByID provides a mock function with given fields: id func (_m *MockObjectStore) GetInboundLinksByID(id string) ([]string, error) { ret := _m.Called(id) @@ -2296,13 +2362,12 @@ func (_c *MockObjectStore_UpdatePendingLocalDetails_Call) RunAndReturn(run func( return _c } -type mockConstructorTestingTNewMockObjectStore interface { +// NewMockObjectStore creates a new instance of MockObjectStore. 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 NewMockObjectStore(t interface { mock.TestingT Cleanup(func()) -} - -// NewMockObjectStore creates a new instance of MockObjectStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockObjectStore(t mockConstructorTestingTNewMockObjectStore) *MockObjectStore { +}) *MockObjectStore { mock := &MockObjectStore{} mock.Mock.Test(t) diff --git a/util/testMock/objectstore_mock.go b/util/testMock/objectstore_mock.go index 42bdaea9f..5d9061bdf 100644 --- a/util/testMock/objectstore_mock.go +++ b/util/testMock/objectstore_mock.go @@ -76,17 +76,21 @@ func (mr *MockObjectStoreMockRecorder) Close(arg0 any) *gomock.Call { } // DeleteDetails mocks base method. -func (m *MockObjectStore) DeleteDetails(arg0 string) error { +func (m *MockObjectStore) DeleteDetails(arg0 ...string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteDetails", arg0) + varargs := []any{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "DeleteDetails", varargs...) ret0, _ := ret[0].(error) return ret0 } // DeleteDetails indicates an expected call of DeleteDetails. -func (mr *MockObjectStoreMockRecorder) DeleteDetails(arg0 any) *gomock.Call { +func (mr *MockObjectStoreMockRecorder) DeleteDetails(arg0 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDetails", reflect.TypeOf((*MockObjectStore)(nil).DeleteDetails), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDetails", reflect.TypeOf((*MockObjectStore)(nil).DeleteDetails), arg0...) } // DeleteObject mocks base method. @@ -241,6 +245,21 @@ func (mr *MockObjectStoreMockRecorder) GetDetails(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDetails", reflect.TypeOf((*MockObjectStore)(nil).GetDetails), arg0) } +// GetGlobalChecksums mocks base method. +func (m *MockObjectStore) GetGlobalChecksums() (*model.ObjectStoreChecksums, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetGlobalChecksums") + ret0, _ := ret[0].(*model.ObjectStoreChecksums) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetGlobalChecksums indicates an expected call of GetGlobalChecksums. +func (mr *MockObjectStoreMockRecorder) GetGlobalChecksums() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGlobalChecksums", reflect.TypeOf((*MockObjectStore)(nil).GetGlobalChecksums)) +} + // GetInboundLinksByID mocks base method. func (m *MockObjectStore) GetInboundLinksByID(arg0 string) ([]string, error) { m.ctrl.T.Helper()