From bef4a48fffeafc96ab7c6e7c6c2e28ed388e3824 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 22 Dec 2023 17:36:48 +0100 Subject: [PATCH] GO-2548 Fix space tests --- .../mock_objectstore/mock_ObjectStore.go | 154 +++++++----------- .../mock_clientspace/mock_Space.go | 4 - space/service.go | 8 +- space/service_test.go | 3 +- 4 files changed, 66 insertions(+), 103 deletions(-) diff --git a/pkg/lib/localstore/objectstore/mock_objectstore/mock_ObjectStore.go b/pkg/lib/localstore/objectstore/mock_objectstore/mock_ObjectStore.go index 77fbff381..dfc345aa4 100644 --- a/pkg/lib/localstore/objectstore/mock_objectstore/mock_ObjectStore.go +++ b/pkg/lib/localstore/objectstore/mock_objectstore/mock_ObjectStore.go @@ -19,8 +19,6 @@ import ( model "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - objectstore "github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore" - pbtypes "github.com/anyproto/anytype-heart/util/pbtypes" relationutils "github.com/anyproto/anytype-heart/core/relationutils" @@ -239,6 +237,65 @@ func (_c *MockObjectStore_DeleteDetails_Call) RunAndReturn(run func(...string) e return _c } +// DeleteLinks provides a mock function with given fields: id +func (_m *MockObjectStore) DeleteLinks(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...) + + if len(ret) == 0 { + panic("no return value specified for DeleteLinks") + } + + var r0 error + if rf, ok := ret.Get(0).(func(...string) error); ok { + r0 = rf(id...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockObjectStore_DeleteLinks_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteLinks' +type MockObjectStore_DeleteLinks_Call struct { + *mock.Call +} + +// DeleteLinks is a helper method to define mock.On call +// - id ...string +func (_e *MockObjectStore_Expecter) DeleteLinks(id ...interface{}) *MockObjectStore_DeleteLinks_Call { + return &MockObjectStore_DeleteLinks_Call{Call: _e.mock.On("DeleteLinks", + append([]interface{}{}, id...)...)} +} + +func (_c *MockObjectStore_DeleteLinks_Call) Run(run func(id ...string)) *MockObjectStore_DeleteLinks_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]string, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(string) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *MockObjectStore_DeleteLinks_Call) Return(_a0 error) *MockObjectStore_DeleteLinks_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockObjectStore_DeleteLinks_Call) RunAndReturn(run func(...string) error) *MockObjectStore_DeleteLinks_Call { + _c.Call.Return(run) + return _c +} + // DeleteObject provides a mock function with given fields: id func (_m *MockObjectStore) DeleteObject(id string) error { ret := _m.Called(id) @@ -331,52 +388,6 @@ func (_c *MockObjectStore_DeleteVirtualSpace_Call) RunAndReturn(run func(string) return _c } -// EraseIndexes provides a mock function with given fields: spaceId -func (_m *MockObjectStore) EraseIndexes(spaceId string) error { - ret := _m.Called(spaceId) - - if len(ret) == 0 { - panic("no return value specified for EraseIndexes") - } - - var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { - r0 = rf(spaceId) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockObjectStore_EraseIndexes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EraseIndexes' -type MockObjectStore_EraseIndexes_Call struct { - *mock.Call -} - -// EraseIndexes is a helper method to define mock.On call -// - spaceId string -func (_e *MockObjectStore_Expecter) EraseIndexes(spaceId interface{}) *MockObjectStore_EraseIndexes_Call { - return &MockObjectStore_EraseIndexes_Call{Call: _e.mock.On("EraseIndexes", spaceId)} -} - -func (_c *MockObjectStore_EraseIndexes_Call) Run(run func(spaceId string)) *MockObjectStore_EraseIndexes_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *MockObjectStore_EraseIndexes_Call) Return(_a0 error) *MockObjectStore_EraseIndexes_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockObjectStore_EraseIndexes_Call) RunAndReturn(run func(string) error) *MockObjectStore_EraseIndexes_Call { - _c.Call.Return(run) - return _c -} - // FTSearch provides a mock function with given fields: func (_m *MockObjectStore) FTSearch() ftsearch.FTSearch { ret := _m.Called() @@ -2621,53 +2632,6 @@ func (_c *MockObjectStore_SaveVirtualSpace_Call) RunAndReturn(run func(string) e return _c } -// SubscribeBacklinksUpdate provides a mock function with given fields: -func (_m *MockObjectStore) SubscribeBacklinksUpdate() <-chan objectstore.BacklinksUpdateInfo { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for SubscribeBacklinksUpdate") - } - - var r0 <-chan objectstore.BacklinksUpdateInfo - if rf, ok := ret.Get(0).(func() <-chan objectstore.BacklinksUpdateInfo); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan objectstore.BacklinksUpdateInfo) - } - } - - return r0 -} - -// MockObjectStore_SubscribeBacklinksUpdate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SubscribeBacklinksUpdate' -type MockObjectStore_SubscribeBacklinksUpdate_Call struct { - *mock.Call -} - -// SubscribeBacklinksUpdate is a helper method to define mock.On call -func (_e *MockObjectStore_Expecter) SubscribeBacklinksUpdate() *MockObjectStore_SubscribeBacklinksUpdate_Call { - return &MockObjectStore_SubscribeBacklinksUpdate_Call{Call: _e.mock.On("SubscribeBacklinksUpdate")} -} - -func (_c *MockObjectStore_SubscribeBacklinksUpdate_Call) Run(run func()) *MockObjectStore_SubscribeBacklinksUpdate_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *MockObjectStore_SubscribeBacklinksUpdate_Call) Return(_a0 <-chan objectstore.BacklinksUpdateInfo) *MockObjectStore_SubscribeBacklinksUpdate_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockObjectStore_SubscribeBacklinksUpdate_Call) RunAndReturn(run func() <-chan objectstore.BacklinksUpdateInfo) *MockObjectStore_SubscribeBacklinksUpdate_Call { - _c.Call.Return(run) - return _c -} - // SubscribeForAll provides a mock function with given fields: callback func (_m *MockObjectStore) SubscribeForAll(callback func(database.Record)) { _m.Called(callback) diff --git a/space/clientspace/mock_clientspace/mock_Space.go b/space/clientspace/mock_clientspace/mock_Space.go index c095f75c1..ed90cf36b 100644 --- a/space/clientspace/mock_clientspace/mock_Space.go +++ b/space/clientspace/mock_clientspace/mock_Space.go @@ -124,10 +124,6 @@ func (_m *MockSpace) CreateMandatoryObjects(ctx context.Context, space smartbloc panic("no return value specified for CreateMandatoryObjects") } - if len(ret) == 0 { - panic("no return value specified for CreateMandatoryObjects") - } - var r0 error if rf, ok := ret.Get(0).(func(context.Context, smartblock.Space) error); ok { r0 = rf(ctx, space) diff --git a/space/service.go b/space/service.go index 0e178e8df..e8c0dc9c5 100644 --- a/space/service.go +++ b/space/service.go @@ -17,6 +17,7 @@ import ( "github.com/anyproto/anytype-heart/pkg/lib/localstore/addr" "github.com/anyproto/anytype-heart/space/clientspace" "github.com/anyproto/anytype-heart/space/internal/spacecontroller" + "github.com/anyproto/anytype-heart/space/internal/spaceprocess/mode" "github.com/anyproto/anytype-heart/space/spacecore" "github.com/anyproto/anytype-heart/space/spacefactory" "github.com/anyproto/anytype-heart/space/spaceinfo" @@ -231,10 +232,11 @@ func (s *service) Close(ctx context.Context) error { func (s *service) allIDs() (ids []string) { s.mu.Lock() defer s.mu.Unlock() - for id := range s.spaceControllers { - if id != addr.AnytypeMarketplaceWorkspace { - ids = append(ids, id) + for id, sc := range s.spaceControllers { + if id == addr.AnytypeMarketplaceWorkspace || sc.Mode() != mode.ModeLoading { + continue } + ids = append(ids, id) } return } diff --git a/space/service_test.go b/space/service_test.go index 0c7bb8284..3b5c863d7 100644 --- a/space/service_test.go +++ b/space/service_test.go @@ -17,6 +17,7 @@ import ( "github.com/anyproto/anytype-heart/space/clientspace" "github.com/anyproto/anytype-heart/space/clientspace/mock_clientspace" "github.com/anyproto/anytype-heart/space/internal/spacecontroller/mock_spacecontroller" + "github.com/anyproto/anytype-heart/space/internal/spaceprocess/mode" "github.com/anyproto/anytype-heart/space/internal/techspace/mock_techspace" "github.com/anyproto/anytype-heart/space/spacecore/mock_spacecore" "github.com/anyproto/anytype-heart/space/spacefactory/mock_spacefactory" @@ -39,7 +40,6 @@ func TestService_Init(t *testing.T) { fx := newFixture(t, true) defer fx.finish(t) }) - } func newFixture(t *testing.T, newAccount bool) *fixture { @@ -110,6 +110,7 @@ func (fx *fixture) expectRun(t *testing.T, newAccount bool) { lw := lwMock{clientSpace} prCtrl.EXPECT().Current().Return(lw) } + prCtrl.EXPECT().Mode().Return(mode.ModeLoading) ts.EXPECT().Close(mock.Anything).Return(nil) mpCtrl.EXPECT().Close(mock.Anything).Return(nil) prCtrl.EXPECT().Close(mock.Anything).Return(nil)