From d244f4153ab5b333d13c59a4082bfae044129b47 Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Mon, 30 Sep 2024 12:35:16 +0200 Subject: [PATCH 1/7] GO-3526: add file drop in collection Signed-off-by: AnastasiaShemyakinskaya --- .mockery.yaml | 3 + .../mock_detailservice/mock_Service.go | 48 ------ core/block/editor/file/file.go | 36 ++++- core/block/editor/file/file_test.go | 151 +++++++++++++++++- 4 files changed, 181 insertions(+), 57 deletions(-) diff --git a/.mockery.yaml b/.mockery.yaml index dbc4a0124d..e67a342e92 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -217,5 +217,8 @@ packages: interfaces: Downloader: github.com/anyproto/anytype-heart/core/block/detailservice: + interfaces: + Service: + github.com/anyproto/anytype-heart/core/files/fileuploader: interfaces: Service: \ No newline at end of file diff --git a/core/block/detailservice/mock_detailservice/mock_Service.go b/core/block/detailservice/mock_detailservice/mock_Service.go index 3ff60d154d..2c0338b670 100644 --- a/core/block/detailservice/mock_detailservice/mock_Service.go +++ b/core/block/detailservice/mock_detailservice/mock_Service.go @@ -833,54 +833,6 @@ func (_c *MockService_SetListIsFavorite_Call) RunAndReturn(run func([]string, bo return _c } -// SetSource provides a mock function with given fields: ctx, objectId, source -func (_m *MockService) SetSource(ctx session.Context, objectId string, source []string) error { - ret := _m.Called(ctx, objectId, source) - - if len(ret) == 0 { - panic("no return value specified for SetSource") - } - - var r0 error - if rf, ok := ret.Get(0).(func(session.Context, string, []string) error); ok { - r0 = rf(ctx, objectId, source) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockService_SetSource_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetSource' -type MockService_SetSource_Call struct { - *mock.Call -} - -// SetSource is a helper method to define mock.On call -// - ctx session.Context -// - objectId string -// - source []string -func (_e *MockService_Expecter) SetSource(ctx interface{}, objectId interface{}, source interface{}) *MockService_SetSource_Call { - return &MockService_SetSource_Call{Call: _e.mock.On("SetSource", ctx, objectId, source)} -} - -func (_c *MockService_SetSource_Call) Run(run func(ctx session.Context, objectId string, source []string)) *MockService_SetSource_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(session.Context), args[1].(string), args[2].([]string)) - }) - return _c -} - -func (_c *MockService_SetSource_Call) Return(_a0 error) *MockService_SetSource_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockService_SetSource_Call) RunAndReturn(run func(session.Context, string, []string) error) *MockService_SetSource_Call { - _c.Call.Return(run) - return _c -} - // SetSpaceInfo provides a mock function with given fields: spaceId, details func (_m *MockService) SetSpaceInfo(spaceId string, details *types.Struct) error { ret := _m.Called(spaceId, details) diff --git a/core/block/editor/file/file.go b/core/block/editor/file/file.go index 3367680adb..22f66454e8 100644 --- a/core/block/editor/file/file.go +++ b/core/block/editor/file/file.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "strings" "sync" "sync/atomic" @@ -16,6 +17,7 @@ import ( "github.com/anyproto/anytype-heart/core/block/cache" "github.com/anyproto/anytype-heart/core/block/editor/smartblock" "github.com/anyproto/anytype-heart/core/block/editor/state" + "github.com/anyproto/anytype-heart/core/block/editor/template" "github.com/anyproto/anytype-heart/core/block/process" "github.com/anyproto/anytype-heart/core/block/simple" "github.com/anyproto/anytype-heart/core/block/simple/file" @@ -220,8 +222,10 @@ func (sf *sfile) updateFile(ctx session.Context, id, groupId string, apply func( } func (sf *sfile) DropFiles(req pb.RpcFileDropRequest) (err error) { - if err = sf.Restrictions().Object.Check(model.Restrictions_Blocks); err != nil { - return err + if layout, ok := sf.Layout(); !ok || layout != model.ObjectType_collection { + if err = sf.Restrictions().Object.Check(model.Restrictions_Blocks); err != nil { + return err + } } proc := &dropFilesProcess{ spaceID: sf.SpaceID(), @@ -247,7 +251,6 @@ func (sf *sfile) dropFilesCreateStructure(groupId, targetId string, pos model.Bl for _, entry := range entries { var blockId, pageId string if entry.isDir { - if err = sf.Apply(s); err != nil { return } @@ -303,6 +306,14 @@ func (sf *sfile) dropFilesSetInfo(info dropFileInfo) (err error) { s.Unlink(info.blockId) return sf.Apply(s) } + if layout, ok := sf.Layout(); ok && layout == model.ObjectType_collection { + s := sf.NewState() + store := s.GetStoreSlice(template.CollectionStoreKey) + if !slices.Contains(store, info.file.TargetObjectId) { + s.UpdateStoreSlice(template.CollectionStoreKey, append(store, info.file.TargetObjectId)) + } + return sf.Apply(s) + } return sf.UpdateFile(info.blockId, info.groupId, func(f file.Block) error { if info.err != nil || info.file == nil || info.file.State == model.BlockContentFile_Error { if info.err != nil { @@ -476,6 +487,25 @@ func (dp *dropFilesProcess) Start(rootId, targetId string, pos model.BlockPositi return } err = cache.Do(dp.picker, smartBlockIds[idx], func(sb File) error { + smartBlock, ok := sb.(smartblock.SmartBlock) + if ok { + if layout, ok := smartBlock.Layout(); ok && layout == model.ObjectType_collection { + for _, entry := range flatEntries[idx] { + if entry.isDir { + smartBlockIds = append(smartBlockIds, rootId) + flatEntries = append(flatEntries, entry.child) + atomic.AddInt64(&dp.done, 1) + continue + } + in <- &dropFileInfo{ + pageId: smartBlockIds[idx], + path: entry.path, + name: entry.name, + } + } + return nil + } + } sbHandler, ok := sb.(dropFilesHandler) if !ok { isContinue = idx != 0 diff --git a/core/block/editor/file/file_test.go b/core/block/editor/file/file_test.go index 46baafc1b3..59bb9bc628 100644 --- a/core/block/editor/file/file_test.go +++ b/core/block/editor/file/file_test.go @@ -1,16 +1,27 @@ package file import ( + "context" "errors" + "os" + "path/filepath" "testing" + "github.com/anyproto/any-sync/app" + "github.com/gogo/protobuf/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/anyproto/anytype-heart/core/block/cache/mock_cache" "github.com/anyproto/anytype-heart/core/block/editor/smartblock/smarttest" + "github.com/anyproto/anytype-heart/core/block/process" "github.com/anyproto/anytype-heart/core/block/restriction" + "github.com/anyproto/anytype-heart/core/block/simple/file" + "github.com/anyproto/anytype-heart/core/event/mock_event" + "github.com/anyproto/anytype-heart/core/files" + "github.com/anyproto/anytype-heart/core/files/fileuploader" + "github.com/anyproto/anytype-heart/core/files/fileuploader/mock_fileuploader" "github.com/anyproto/anytype-heart/pb" "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" @@ -21,21 +32,31 @@ import ( type fileFixture struct { sfile - pickerFx *mock_cache.MockObjectGetter - sb *smarttest.SmartTest + pickerFx *mock_cache.MockObjectGetter + sb *smarttest.SmartTest + mockSender *mock_event.MockSender } func newFixture(t *testing.T) *fileFixture { picker := mock_cache.NewMockObjectGetter(t) sb := smarttest.New("root") + mockSender := mock_event.NewMockSender(t) fx := &fileFixture{ - pickerFx: picker, - sb: sb, + pickerFx: picker, + sb: sb, + mockSender: mockSender, } + a := &app.App{} + a.Register(testutil.PrepareMock(context.Background(), a, mockSender)) + service := process.New() + err := service.Init(a) + assert.Nil(t, err) + fx.sfile = sfile{ - SmartBlock: sb, - picker: picker, + SmartBlock: sb, + picker: picker, + processService: service, } return fx } @@ -119,4 +140,122 @@ func TestDropFiles(t *testing.T) { assert.Error(t, err) assert.True(t, errors.Is(err, restriction.ErrRestricted)) }) + t.Run("drop files in collection", func(t *testing.T) { + // given + dir := t.TempDir() + file, err := os.Create(filepath.Join(dir, "test")) + assert.Nil(t, err) + + fx := newFixture(t) + st := fx.sb.Doc.NewState() + st.SetDetail(bundle.RelationKeyLayout.String(), pbtypes.Int64(int64(model.ObjectType_collection))) + fx.sb.Doc = st + fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil) + fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() + + service := mock_fileuploader.NewMockService(t) + service.EXPECT().NewUploader(mock.Anything, mock.Anything).Return(&stubUploader{}).Maybe() + fx.fileUploaderFactory = service + + // when + err = fx.sfile.DropFiles(pb.RpcFileDropRequest{ + ContextId: "root", + LocalFilePaths: []string{file.Name()}, + }) + + // then + assert.Nil(t, err) + }) + t.Run("drop dir in collection", func(t *testing.T) { + // given + dir := t.TempDir() + _, err := os.Create(filepath.Join(dir, "test")) + assert.Nil(t, err) + + fx := newFixture(t) + st := fx.sb.Doc.NewState() + st.SetDetail(bundle.RelationKeyLayout.String(), pbtypes.Int64(int64(model.ObjectType_collection))) + fx.sb.Doc = st + fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil) + fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() + + service := mock_fileuploader.NewMockService(t) + service.EXPECT().NewUploader(mock.Anything, mock.Anything).Return(&stubUploader{}).Maybe() + fx.fileUploaderFactory = service + + // when + err = fx.sfile.DropFiles(pb.RpcFileDropRequest{ + ContextId: "root", + LocalFilePaths: []string{dir}, + }) + + // then + assert.Nil(t, err) + }) +} + +type stubUploader struct { + name, path string +} + +func (s *stubUploader) SetBlock(block file.Block) fileuploader.Uploader { + return s +} + +func (s *stubUploader) SetName(name string) fileuploader.Uploader { + s.name = name + return s +} + +func (s *stubUploader) SetType(tp model.BlockContentFileType) fileuploader.Uploader { + return s +} + +func (s *stubUploader) SetStyle(tp model.BlockContentFileStyle) fileuploader.Uploader { + return s +} + +func (s *stubUploader) SetAdditionalDetails(details *types.Struct) fileuploader.Uploader { + return s +} + +func (s *stubUploader) SetBytes(b []byte) fileuploader.Uploader { + return s +} + +func (s *stubUploader) SetUrl(url string) fileuploader.Uploader { + return s +} + +func (s *stubUploader) SetFile(path string) fileuploader.Uploader { + s.path = path + return s +} + +func (s *stubUploader) SetLastModifiedDate() fileuploader.Uploader { + return s +} + +func (s *stubUploader) SetGroupId(groupId string) fileuploader.Uploader { + return s +} + +func (s *stubUploader) SetCustomEncryptionKeys(keys map[string]string) fileuploader.Uploader { + return s +} + +func (s *stubUploader) AddOptions(options ...files.AddOption) fileuploader.Uploader { + return s +} + +func (s *stubUploader) AsyncUpdates(smartBlockId string) fileuploader.Uploader { + return s +} + +func (s *stubUploader) Upload(ctx context.Context) (result fileuploader.UploadResult) { + return fileuploader.UploadResult{FileObjectId: "id"} +} + +func (s *stubUploader) UploadAsync(ctx context.Context) (ch chan fileuploader.UploadResult) { + return nil } From 3e3768276b76b4b454fb0844d4337616750eb097 Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Mon, 30 Sep 2024 12:36:36 +0200 Subject: [PATCH 2/7] GO-3526: add mock Signed-off-by: AnastasiaShemyakinskaya --- .../mock_fileuploader/mock_Service.go | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 core/files/fileuploader/mock_fileuploader/mock_Service.go diff --git a/core/files/fileuploader/mock_fileuploader/mock_Service.go b/core/files/fileuploader/mock_fileuploader/mock_Service.go new file mode 100644 index 0000000000..327291132c --- /dev/null +++ b/core/files/fileuploader/mock_fileuploader/mock_Service.go @@ -0,0 +1,178 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_fileuploader + +import ( + app "github.com/anyproto/any-sync/app" + fileuploader "github.com/anyproto/anytype-heart/core/files/fileuploader" + mock "github.com/stretchr/testify/mock" + + objectorigin "github.com/anyproto/anytype-heart/core/domain/objectorigin" +) + +// MockService is an autogenerated mock type for the Service type +type MockService struct { + mock.Mock +} + +type MockService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockService) EXPECT() *MockService_Expecter { + return &MockService_Expecter{mock: &_m.Mock} +} + +// Init provides a mock function with given fields: a +func (_m *MockService) Init(a *app.App) error { + ret := _m.Called(a) + + if len(ret) == 0 { + panic("no return value specified for Init") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*app.App) error); ok { + r0 = rf(a) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockService_Init_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Init' +type MockService_Init_Call struct { + *mock.Call +} + +// Init is a helper method to define mock.On call +// - a *app.App +func (_e *MockService_Expecter) Init(a interface{}) *MockService_Init_Call { + return &MockService_Init_Call{Call: _e.mock.On("Init", a)} +} + +func (_c *MockService_Init_Call) Run(run func(a *app.App)) *MockService_Init_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*app.App)) + }) + return _c +} + +func (_c *MockService_Init_Call) Return(err error) *MockService_Init_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockService_Init_Call) RunAndReturn(run func(*app.App) error) *MockService_Init_Call { + _c.Call.Return(run) + return _c +} + +// Name provides a mock function with given fields: +func (_m *MockService) Name() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Name") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// MockService_Name_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Name' +type MockService_Name_Call struct { + *mock.Call +} + +// Name is a helper method to define mock.On call +func (_e *MockService_Expecter) Name() *MockService_Name_Call { + return &MockService_Name_Call{Call: _e.mock.On("Name")} +} + +func (_c *MockService_Name_Call) Run(run func()) *MockService_Name_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockService_Name_Call) Return(name string) *MockService_Name_Call { + _c.Call.Return(name) + return _c +} + +func (_c *MockService_Name_Call) RunAndReturn(run func() string) *MockService_Name_Call { + _c.Call.Return(run) + return _c +} + +// NewUploader provides a mock function with given fields: spaceId, origin +func (_m *MockService) NewUploader(spaceId string, origin objectorigin.ObjectOrigin) fileuploader.Uploader { + ret := _m.Called(spaceId, origin) + + if len(ret) == 0 { + panic("no return value specified for NewUploader") + } + + var r0 fileuploader.Uploader + if rf, ok := ret.Get(0).(func(string, objectorigin.ObjectOrigin) fileuploader.Uploader); ok { + r0 = rf(spaceId, origin) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(fileuploader.Uploader) + } + } + + return r0 +} + +// MockService_NewUploader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewUploader' +type MockService_NewUploader_Call struct { + *mock.Call +} + +// NewUploader is a helper method to define mock.On call +// - spaceId string +// - origin objectorigin.ObjectOrigin +func (_e *MockService_Expecter) NewUploader(spaceId interface{}, origin interface{}) *MockService_NewUploader_Call { + return &MockService_NewUploader_Call{Call: _e.mock.On("NewUploader", spaceId, origin)} +} + +func (_c *MockService_NewUploader_Call) Run(run func(spaceId string, origin objectorigin.ObjectOrigin)) *MockService_NewUploader_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(objectorigin.ObjectOrigin)) + }) + return _c +} + +func (_c *MockService_NewUploader_Call) Return(_a0 fileuploader.Uploader) *MockService_NewUploader_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockService_NewUploader_Call) RunAndReturn(run func(string, objectorigin.ObjectOrigin) fileuploader.Uploader) *MockService_NewUploader_Call { + _c.Call.Return(run) + return _c +} + +// NewMockService creates a new instance of MockService. 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 NewMockService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockService { + mock := &MockService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} From d340a602f4d66aa21f20d6205ad5f0ded63da1da Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Mon, 30 Sep 2024 13:15:35 +0200 Subject: [PATCH 3/7] GO-3526: fix Signed-off-by: AnastasiaShemyakinskaya --- core/block/editor/file/file.go | 1 - 1 file changed, 1 deletion(-) diff --git a/core/block/editor/file/file.go b/core/block/editor/file/file.go index 22f66454e8..a8cd3034d0 100644 --- a/core/block/editor/file/file.go +++ b/core/block/editor/file/file.go @@ -494,7 +494,6 @@ func (dp *dropFilesProcess) Start(rootId, targetId string, pos model.BlockPositi if entry.isDir { smartBlockIds = append(smartBlockIds, rootId) flatEntries = append(flatEntries, entry.child) - atomic.AddInt64(&dp.done, 1) continue } in <- &dropFileInfo{ From c70733bdffbc034a821d9bd00aa04cf7890437f2 Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Tue, 8 Oct 2024 17:33:10 +0200 Subject: [PATCH 4/7] GO-4162: refactoring Signed-off-by: AnastasiaShemyakinskaya --- core/block/editor/file/file.go | 80 ++++++++++++++++--------- core/block/editor/file/file_test.go | 91 +++++++++++++++++++++++++++-- 2 files changed, 139 insertions(+), 32 deletions(-) diff --git a/core/block/editor/file/file.go b/core/block/editor/file/file.go index a8cd3034d0..050ab21077 100644 --- a/core/block/editor/file/file.go +++ b/core/block/editor/file/file.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "path/filepath" - "slices" "strings" "sync" "sync/atomic" @@ -222,7 +221,7 @@ func (sf *sfile) updateFile(ctx session.Context, id, groupId string, apply func( } func (sf *sfile) DropFiles(req pb.RpcFileDropRequest) (err error) { - if layout, ok := sf.Layout(); !ok || layout != model.ObjectType_collection { + if !isCollection(sf) { if err = sf.Restrictions().Object.Check(model.Restrictions_Blocks); err != nil { return err } @@ -237,7 +236,7 @@ func (sf *sfile) DropFiles(req pb.RpcFileDropRequest) (err error) { return } var ch = make(chan error) - go proc.Start(sf.RootId(), req.DropTargetId, req.Position, ch) + go proc.Start(sf, req.DropTargetId, req.Position, ch) err = <-ch return } @@ -306,11 +305,10 @@ func (sf *sfile) dropFilesSetInfo(info dropFileInfo) (err error) { s.Unlink(info.blockId) return sf.Apply(s) } - if layout, ok := sf.Layout(); ok && layout == model.ObjectType_collection { + if isCollection(sf) { s := sf.NewState() - store := s.GetStoreSlice(template.CollectionStoreKey) - if !slices.Contains(store, info.file.TargetObjectId) { - s.UpdateStoreSlice(template.CollectionStoreKey, append(store, info.file.TargetObjectId)) + if !s.HasInStore([]string{info.file.TargetObjectId}) { + s.UpdateStoreSlice(template.CollectionStoreKey, append(s.GetStoreSlice(template.CollectionStoreKey), info.file.TargetObjectId)) } return sf.Apply(s) } @@ -461,7 +459,7 @@ func (dp *dropFilesProcess) readdir(entry *dropFileEntry, allowSymlinks bool) (o return true, nil } -func (dp *dropFilesProcess) Start(rootId, targetId string, pos model.BlockPosition, rootDone chan error) { +func (dp *dropFilesProcess) Start(file smartblock.SmartBlock, targetId string, pos model.BlockPosition, rootDone chan error) { dp.id = uuid.New().String() dp.doneCh = make(chan struct{}) dp.cancel = make(chan struct{}) @@ -480,6 +478,47 @@ func (dp *dropFilesProcess) Start(rootId, targetId string, pos model.BlockPositi go dp.addFilesWorker(wg, in) } + if isCollection(file) { + dp.handleDragAndDropInCollection(file.RootId(), dp.root.child, rootDone, in) + } else { + dp.handleDragAndDropInDocument(file.RootId(), targetId, pos, rootDone, in) + } + wg.Wait() + return +} + +func (dp *dropFilesProcess) handleDragAndDropInCollection(rootId string, droppedFiles []*dropFileEntry, rootDone chan error, in chan *dropFileInfo) { + close(rootDone) + filesToUpload := dp.getFilesToUploadFromDirs(droppedFiles) + for _, entry := range filesToUpload { + in <- &dropFileInfo{ + pageId: rootId, + path: entry.path, + name: entry.name, + } + } + close(in) +} + +func (dp *dropFilesProcess) getFilesToUploadFromDirs(droppedFiles []*dropFileEntry) []*dropFileEntry { + var ( + stack []*dropFileEntry + totalFiles []*dropFileEntry + ) + stack = append(stack, droppedFiles...) + for len(stack) > 0 { + entry := stack[len(stack)-1] + stack = stack[:len(stack)-1] + if entry.isDir { + stack = append(stack, entry.child...) + } else { + totalFiles = append(totalFiles, entry) + } + } + return totalFiles +} + +func (dp *dropFilesProcess) handleDragAndDropInDocument(rootId, targetId string, pos model.BlockPosition, rootDone chan error, in chan *dropFileInfo) { var flatEntries = [][]*dropFileEntry{dp.root.child} var smartBlockIds = []string{rootId} var handleLevel = func(idx int) (isContinue bool, err error) { @@ -487,24 +526,6 @@ func (dp *dropFilesProcess) Start(rootId, targetId string, pos model.BlockPositi return } err = cache.Do(dp.picker, smartBlockIds[idx], func(sb File) error { - smartBlock, ok := sb.(smartblock.SmartBlock) - if ok { - if layout, ok := smartBlock.Layout(); ok && layout == model.ObjectType_collection { - for _, entry := range flatEntries[idx] { - if entry.isDir { - smartBlockIds = append(smartBlockIds, rootId) - flatEntries = append(flatEntries, entry.child) - continue - } - in <- &dropFileInfo{ - pageId: smartBlockIds[idx], - path: entry.path, - name: entry.name, - } - } - return nil - } - } sbHandler, ok := sb.(dropFilesHandler) if !ok { isContinue = idx != 0 @@ -562,8 +583,6 @@ func (dp *dropFilesProcess) Start(rootId, targetId string, pos model.BlockPositi idx++ } close(in) - wg.Wait() - return } func (dp *dropFilesProcess) addFilesWorker(wg *sync.WaitGroup, in chan *dropFileInfo) { @@ -619,3 +638,8 @@ func (dp *dropFilesProcess) apply(f *dropFileInfo) (err error) { return sbHandler.dropFilesSetInfo(*f) }) } + +func isCollection(smartBlock smartblock.SmartBlock) bool { + layout, ok := smartBlock.Layout() + return ok && layout == model.ObjectType_collection +} diff --git a/core/block/editor/file/file_test.go b/core/block/editor/file/file_test.go index 59bb9bc628..b6a56fe4ee 100644 --- a/core/block/editor/file/file_test.go +++ b/core/block/editor/file/file_test.go @@ -7,12 +7,16 @@ import ( "path/filepath" "testing" + "github.com/anyproto/any-sync/accountservice/mock_accountservice" "github.com/anyproto/any-sync/app" + "github.com/anyproto/any-sync/commonfile/fileservice" "github.com/gogo/protobuf/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + "github.com/anyproto/anytype-heart/core/anytype/config" "github.com/anyproto/anytype-heart/core/block/cache/mock_cache" "github.com/anyproto/anytype-heart/core/block/editor/smartblock/smarttest" "github.com/anyproto/anytype-heart/core/block/process" @@ -22,8 +26,16 @@ import ( "github.com/anyproto/anytype-heart/core/files" "github.com/anyproto/anytype-heart/core/files/fileuploader" "github.com/anyproto/anytype-heart/core/files/fileuploader/mock_fileuploader" + "github.com/anyproto/anytype-heart/core/filestorage" + "github.com/anyproto/anytype-heart/core/filestorage/filesync" + "github.com/anyproto/anytype-heart/core/filestorage/rpcstore" + wallet2 "github.com/anyproto/anytype-heart/core/wallet" + "github.com/anyproto/anytype-heart/core/wallet/mock_wallet" "github.com/anyproto/anytype-heart/pb" "github.com/anyproto/anytype-heart/pkg/lib/bundle" + "github.com/anyproto/anytype-heart/pkg/lib/datastore" + "github.com/anyproto/anytype-heart/pkg/lib/localstore/filestore" + "github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" "github.com/anyproto/anytype-heart/tests/blockbuilder" "github.com/anyproto/anytype-heart/tests/testutil" @@ -140,7 +152,7 @@ func TestDropFiles(t *testing.T) { assert.Error(t, err) assert.True(t, errors.Is(err, restriction.ErrRestricted)) }) - t.Run("drop files in collection", func(t *testing.T) { + t.Run("drop files in collection - no restriction error", func(t *testing.T) { // given dir := t.TempDir() file, err := os.Create(filepath.Join(dir, "test")) @@ -150,7 +162,7 @@ func TestDropFiles(t *testing.T) { st := fx.sb.Doc.NewState() st.SetDetail(bundle.RelationKeyLayout.String(), pbtypes.Int64(int64(model.ObjectType_collection))) fx.sb.Doc = st - fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil) + fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil).Maybe() fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() service := mock_fileuploader.NewMockService(t) @@ -166,7 +178,7 @@ func TestDropFiles(t *testing.T) { // then assert.Nil(t, err) }) - t.Run("drop dir in collection", func(t *testing.T) { + t.Run("drop dir in collection - no restriction error", func(t *testing.T) { // given dir := t.TempDir() _, err := os.Create(filepath.Join(dir, "test")) @@ -176,7 +188,7 @@ func TestDropFiles(t *testing.T) { st := fx.sb.Doc.NewState() st.SetDetail(bundle.RelationKeyLayout.String(), pbtypes.Int64(int64(model.ObjectType_collection))) fx.sb.Doc = st - fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil) + fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil).Maybe() fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() service := mock_fileuploader.NewMockService(t) @@ -192,6 +204,77 @@ func TestDropFiles(t *testing.T) { // then assert.Nil(t, err) }) + t.Run("drop files in collection - success", func(t *testing.T) { + // given + dir := t.TempDir() + file, err := os.Create(filepath.Join(dir, "test")) + assert.Nil(t, err) + + fx := newFixture(t) + st := fx.sb.Doc.NewState() + st.SetDetail(bundle.RelationKeyLayout.String(), pbtypes.Int64(int64(model.ObjectType_collection))) + fx.sb.Doc = st + fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil).Maybe() + fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() + fx.fileUploaderFactory = prepareFileService(t) + // when + proc := &dropFilesProcess{ + spaceID: fx.SpaceID(), + processService: fx.processService, + picker: fx.picker, + fileUploaderFactory: fx.fileUploaderFactory, + } + if err = proc.Init([]string{file.Name()}); err != nil { + return + } + var ch = make(chan error) + go proc.Start(fx, "", model.Block_Bottom, ch) + err = <-ch + + // then + assert.Nil(t, err) + }) +} + +func prepareFileService(t *testing.T) fileuploader.Service { + dataStoreProvider, err := datastore.NewInMemory() + require.NoError(t, err) + + blockStorage := filestorage.NewInMemory() + + rpcStore := rpcstore.NewInMemoryStore(1024) + rpcStoreService := rpcstore.NewInMemoryService(rpcStore) + commonFileService := fileservice.New() + fileSyncService := filesync.New() + objectStore := objectstore.NewStoreFixture(t) + eventSender := mock_event.NewMockSender(t) + eventSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() + + ctx := context.Background() + ctrl := gomock.NewController(t) + wallet := mock_wallet.NewMockWallet(t) + wallet.EXPECT().Name().Return(wallet2.CName) + wallet.EXPECT().RepoPath().Return("repo/path") + + a := new(app.App) + a.Register(dataStoreProvider) + a.Register(filestore.New()) + a.Register(commonFileService) + a.Register(fileSyncService) + a.Register(testutil.PrepareMock(ctx, a, eventSender)) + a.Register(blockStorage) + a.Register(objectStore) + a.Register(rpcStoreService) + a.Register(testutil.PrepareMock(ctx, a, mock_accountservice.NewMockService(ctrl))) + a.Register(testutil.PrepareMock(ctx, a, wallet)) + a.Register(&config.Config{DisableFileConfig: true, NetworkMode: pb.RpcAccount_DefaultConfig, PeferYamuxTransport: true}) + err = a.Start(ctx) + require.NoError(t, err) + + service := fileuploader.New() + err = service.Init(a) + assert.Nil(t, err) + return service } type stubUploader struct { From d4757fff2dc1ab455053e1acd281a0fac78a64da Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Tue, 8 Oct 2024 18:44:43 +0200 Subject: [PATCH 5/7] GO-4162: added tests Signed-off-by: AnastasiaShemyakinskaya --- core/block/editor/file/file_test.go | 151 ++++++++++++---------------- 1 file changed, 63 insertions(+), 88 deletions(-) diff --git a/core/block/editor/file/file_test.go b/core/block/editor/file/file_test.go index b6a56fe4ee..0f834936a7 100644 --- a/core/block/editor/file/file_test.go +++ b/core/block/editor/file/file_test.go @@ -19,13 +19,13 @@ import ( "github.com/anyproto/anytype-heart/core/anytype/config" "github.com/anyproto/anytype-heart/core/block/cache/mock_cache" "github.com/anyproto/anytype-heart/core/block/editor/smartblock/smarttest" + "github.com/anyproto/anytype-heart/core/block/editor/template" "github.com/anyproto/anytype-heart/core/block/process" "github.com/anyproto/anytype-heart/core/block/restriction" - "github.com/anyproto/anytype-heart/core/block/simple/file" "github.com/anyproto/anytype-heart/core/event/mock_event" "github.com/anyproto/anytype-heart/core/files" + "github.com/anyproto/anytype-heart/core/files/fileobject/mock_fileobject" "github.com/anyproto/anytype-heart/core/files/fileuploader" - "github.com/anyproto/anytype-heart/core/files/fileuploader/mock_fileuploader" "github.com/anyproto/anytype-heart/core/filestorage" "github.com/anyproto/anytype-heart/core/filestorage/filesync" "github.com/anyproto/anytype-heart/core/filestorage/rpcstore" @@ -33,6 +33,7 @@ import ( "github.com/anyproto/anytype-heart/core/wallet/mock_wallet" "github.com/anyproto/anytype-heart/pb" "github.com/anyproto/anytype-heart/pkg/lib/bundle" + "github.com/anyproto/anytype-heart/pkg/lib/core" "github.com/anyproto/anytype-heart/pkg/lib/datastore" "github.com/anyproto/anytype-heart/pkg/lib/localstore/filestore" "github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore" @@ -164,10 +165,9 @@ func TestDropFiles(t *testing.T) { fx.sb.Doc = st fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil).Maybe() fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() - - service := mock_fileuploader.NewMockService(t) - service.EXPECT().NewUploader(mock.Anything, mock.Anything).Return(&stubUploader{}).Maybe() - fx.fileUploaderFactory = service + mockService := mock_fileobject.NewMockService(t) + mockService.EXPECT().Create(mock.Anything, mock.Anything, mock.Anything).Return("fileObjectId", &types.Struct{Fields: map[string]*types.Value{}}, nil).Maybe() + fx.fileUploaderFactory = prepareFileService(t, fx.mockSender, mockService) // when err = fx.sfile.DropFiles(pb.RpcFileDropRequest{ @@ -190,10 +190,9 @@ func TestDropFiles(t *testing.T) { fx.sb.Doc = st fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil).Maybe() fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() - - service := mock_fileuploader.NewMockService(t) - service.EXPECT().NewUploader(mock.Anything, mock.Anything).Return(&stubUploader{}).Maybe() - fx.fileUploaderFactory = service + mockService := mock_fileobject.NewMockService(t) + mockService.EXPECT().Create(mock.Anything, mock.Anything, mock.Anything).Return("fileObjectId", &types.Struct{Fields: map[string]*types.Value{}}, nil).Maybe() + fx.fileUploaderFactory = prepareFileService(t, fx.mockSender, mockService) // when err = fx.sfile.DropFiles(pb.RpcFileDropRequest{ @@ -214,9 +213,12 @@ func TestDropFiles(t *testing.T) { st := fx.sb.Doc.NewState() st.SetDetail(bundle.RelationKeyLayout.String(), pbtypes.Int64(int64(model.ObjectType_collection))) fx.sb.Doc = st - fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil).Maybe() - fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() - fx.fileUploaderFactory = prepareFileService(t) + fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil) + fx.mockSender.EXPECT().Broadcast(mock.Anything).Return() + mockService := mock_fileobject.NewMockService(t) + mockService.EXPECT().Create(context.Background(), "", mock.Anything).Return("fileObjectId", &types.Struct{Fields: map[string]*types.Value{}}, nil).Maybe() + fx.fileUploaderFactory = prepareFileService(t, fx.mockSender, mockService) + // when proc := &dropFilesProcess{ spaceID: fx.SpaceID(), @@ -224,21 +226,58 @@ func TestDropFiles(t *testing.T) { picker: fx.picker, fileUploaderFactory: fx.fileUploaderFactory, } - if err = proc.Init([]string{file.Name()}); err != nil { - return + err = proc.Init([]string{file.Name()}) + assert.Nil(t, err) + var ch = make(chan error) + proc.Start(fx, "", model.Block_Bottom, ch) + err = <-ch + + // then + assert.Nil(t, err) + storeSlice := fx.NewState().GetStoreSlice(template.CollectionStoreKey) + assert.Len(t, storeSlice, 1) + assert.Equal(t, "fileObjectId", storeSlice[0]) + }) + t.Run("drop dir with file in collection - success", func(t *testing.T) { + // given + dir := t.TempDir() + _, err := os.Create(filepath.Join(dir, "test")) + assert.Nil(t, err) + + fx := newFixture(t) + st := fx.sb.Doc.NewState() + st.SetDetail(bundle.RelationKeyLayout.String(), pbtypes.Int64(int64(model.ObjectType_collection))) + fx.sb.Doc = st + fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil) + fx.mockSender.EXPECT().Broadcast(mock.Anything).Return() + mockService := mock_fileobject.NewMockService(t) + mockService.EXPECT().Create(context.Background(), "", mock.Anything).Return("fileObjectId", &types.Struct{Fields: map[string]*types.Value{}}, nil).Maybe() + fx.fileUploaderFactory = prepareFileService(t, fx.mockSender, mockService) + + // when + proc := &dropFilesProcess{ + spaceID: fx.SpaceID(), + processService: fx.processService, + picker: fx.picker, + fileUploaderFactory: fx.fileUploaderFactory, } + err = proc.Init([]string{dir}) + assert.Nil(t, err) var ch = make(chan error) - go proc.Start(fx, "", model.Block_Bottom, ch) + proc.Start(fx, "", model.Block_Bottom, ch) err = <-ch // then assert.Nil(t, err) + storeSlice := fx.NewState().GetStoreSlice(template.CollectionStoreKey) + assert.Len(t, storeSlice, 1) + assert.Equal(t, "fileObjectId", storeSlice[0]) }) } -func prepareFileService(t *testing.T) fileuploader.Service { +func prepareFileService(t *testing.T, sender *mock_event.MockSender, fileObjectService *mock_fileobject.MockService) fileuploader.Service { dataStoreProvider, err := datastore.NewInMemory() - require.NoError(t, err) + assert.Nil(t, err) blockStorage := filestorage.NewInMemory() @@ -247,8 +286,6 @@ func prepareFileService(t *testing.T) fileuploader.Service { commonFileService := fileservice.New() fileSyncService := filesync.New() objectStore := objectstore.NewStoreFixture(t) - eventSender := mock_event.NewMockSender(t) - eventSender.EXPECT().Broadcast(mock.Anything).Return().Maybe() ctx := context.Background() ctrl := gomock.NewController(t) @@ -261,84 +298,22 @@ func prepareFileService(t *testing.T) fileuploader.Service { a.Register(filestore.New()) a.Register(commonFileService) a.Register(fileSyncService) - a.Register(testutil.PrepareMock(ctx, a, eventSender)) + a.Register(testutil.PrepareMock(ctx, a, sender)) a.Register(blockStorage) a.Register(objectStore) a.Register(rpcStoreService) a.Register(testutil.PrepareMock(ctx, a, mock_accountservice.NewMockService(ctrl))) a.Register(testutil.PrepareMock(ctx, a, wallet)) + a.Register(testutil.PrepareMock(ctx, a, fileObjectService)) a.Register(&config.Config{DisableFileConfig: true, NetworkMode: pb.RpcAccount_DefaultConfig, PeferYamuxTransport: true}) + a.Register(core.NewTempDirService()) + a.Register(testutil.PrepareMock(ctx, a, mock_cache.NewMockObjectGetterComponent(t))) + a.Register(files.New()) err = a.Start(ctx) - require.NoError(t, err) + assert.Nil(t, err) service := fileuploader.New() err = service.Init(a) assert.Nil(t, err) return service } - -type stubUploader struct { - name, path string -} - -func (s *stubUploader) SetBlock(block file.Block) fileuploader.Uploader { - return s -} - -func (s *stubUploader) SetName(name string) fileuploader.Uploader { - s.name = name - return s -} - -func (s *stubUploader) SetType(tp model.BlockContentFileType) fileuploader.Uploader { - return s -} - -func (s *stubUploader) SetStyle(tp model.BlockContentFileStyle) fileuploader.Uploader { - return s -} - -func (s *stubUploader) SetAdditionalDetails(details *types.Struct) fileuploader.Uploader { - return s -} - -func (s *stubUploader) SetBytes(b []byte) fileuploader.Uploader { - return s -} - -func (s *stubUploader) SetUrl(url string) fileuploader.Uploader { - return s -} - -func (s *stubUploader) SetFile(path string) fileuploader.Uploader { - s.path = path - return s -} - -func (s *stubUploader) SetLastModifiedDate() fileuploader.Uploader { - return s -} - -func (s *stubUploader) SetGroupId(groupId string) fileuploader.Uploader { - return s -} - -func (s *stubUploader) SetCustomEncryptionKeys(keys map[string]string) fileuploader.Uploader { - return s -} - -func (s *stubUploader) AddOptions(options ...files.AddOption) fileuploader.Uploader { - return s -} - -func (s *stubUploader) AsyncUpdates(smartBlockId string) fileuploader.Uploader { - return s -} - -func (s *stubUploader) Upload(ctx context.Context) (result fileuploader.UploadResult) { - return fileuploader.UploadResult{FileObjectId: "id"} -} - -func (s *stubUploader) UploadAsync(ctx context.Context) (ch chan fileuploader.UploadResult) { - return nil -} From b301da94ed891a0b131c9d5c2e07ab9127f847c2 Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Tue, 8 Oct 2024 18:52:50 +0200 Subject: [PATCH 6/7] GO-4162: remove not needed mock Signed-off-by: AnastasiaShemyakinskaya --- .mockery.yaml | 3 - .../mock_detailservice/mock_Service.go | 120 ------------ .../mock_fileuploader/mock_Service.go | 178 ------------------ 3 files changed, 301 deletions(-) delete mode 100644 core/files/fileuploader/mock_fileuploader/mock_Service.go diff --git a/.mockery.yaml b/.mockery.yaml index e67a342e92..dbc4a0124d 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -217,8 +217,5 @@ packages: interfaces: Downloader: github.com/anyproto/anytype-heart/core/block/detailservice: - interfaces: - Service: - github.com/anyproto/anytype-heart/core/files/fileuploader: interfaces: Service: \ No newline at end of file diff --git a/core/block/detailservice/mock_detailservice/mock_Service.go b/core/block/detailservice/mock_detailservice/mock_Service.go index 2c0338b670..ad1cdf4ed9 100644 --- a/core/block/detailservice/mock_detailservice/mock_Service.go +++ b/core/block/detailservice/mock_detailservice/mock_Service.go @@ -17,8 +17,6 @@ import ( session "github.com/anyproto/anytype-heart/core/session" - smartblock "github.com/anyproto/anytype-heart/core/block/editor/smartblock" - types "github.com/gogo/protobuf/types" ) @@ -35,124 +33,6 @@ func (_m *MockService) EXPECT() *MockService_Expecter { return &MockService_Expecter{mock: &_m.Mock} } -// GetObject provides a mock function with given fields: ctx, objectID -func (_m *MockService) GetObject(ctx context.Context, objectID string) (smartblock.SmartBlock, error) { - ret := _m.Called(ctx, objectID) - - if len(ret) == 0 { - panic("no return value specified for GetObject") - } - - var r0 smartblock.SmartBlock - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (smartblock.SmartBlock, error)); ok { - return rf(ctx, objectID) - } - if rf, ok := ret.Get(0).(func(context.Context, string) smartblock.SmartBlock); ok { - r0 = rf(ctx, objectID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(smartblock.SmartBlock) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, objectID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockService_GetObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetObject' -type MockService_GetObject_Call struct { - *mock.Call -} - -// GetObject is a helper method to define mock.On call -// - ctx context.Context -// - objectID string -func (_e *MockService_Expecter) GetObject(ctx interface{}, objectID interface{}) *MockService_GetObject_Call { - return &MockService_GetObject_Call{Call: _e.mock.On("GetObject", ctx, objectID)} -} - -func (_c *MockService_GetObject_Call) Run(run func(ctx context.Context, objectID string)) *MockService_GetObject_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string)) - }) - return _c -} - -func (_c *MockService_GetObject_Call) Return(sb smartblock.SmartBlock, err error) *MockService_GetObject_Call { - _c.Call.Return(sb, err) - return _c -} - -func (_c *MockService_GetObject_Call) RunAndReturn(run func(context.Context, string) (smartblock.SmartBlock, error)) *MockService_GetObject_Call { - _c.Call.Return(run) - return _c -} - -// GetObjectByFullID provides a mock function with given fields: ctx, id -func (_m *MockService) GetObjectByFullID(ctx context.Context, id domain.FullID) (smartblock.SmartBlock, error) { - ret := _m.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for GetObjectByFullID") - } - - var r0 smartblock.SmartBlock - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, domain.FullID) (smartblock.SmartBlock, error)); ok { - return rf(ctx, id) - } - if rf, ok := ret.Get(0).(func(context.Context, domain.FullID) smartblock.SmartBlock); ok { - r0 = rf(ctx, id) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(smartblock.SmartBlock) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, domain.FullID) error); ok { - r1 = rf(ctx, id) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockService_GetObjectByFullID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetObjectByFullID' -type MockService_GetObjectByFullID_Call struct { - *mock.Call -} - -// GetObjectByFullID is a helper method to define mock.On call -// - ctx context.Context -// - id domain.FullID -func (_e *MockService_Expecter) GetObjectByFullID(ctx interface{}, id interface{}) *MockService_GetObjectByFullID_Call { - return &MockService_GetObjectByFullID_Call{Call: _e.mock.On("GetObjectByFullID", ctx, id)} -} - -func (_c *MockService_GetObjectByFullID_Call) Run(run func(ctx context.Context, id domain.FullID)) *MockService_GetObjectByFullID_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(domain.FullID)) - }) - return _c -} - -func (_c *MockService_GetObjectByFullID_Call) Return(sb smartblock.SmartBlock, err error) *MockService_GetObjectByFullID_Call { - _c.Call.Return(sb, err) - return _c -} - -func (_c *MockService_GetObjectByFullID_Call) RunAndReturn(run func(context.Context, domain.FullID) (smartblock.SmartBlock, error)) *MockService_GetObjectByFullID_Call { - _c.Call.Return(run) - return _c -} - // Init provides a mock function with given fields: a func (_m *MockService) Init(a *app.App) error { ret := _m.Called(a) diff --git a/core/files/fileuploader/mock_fileuploader/mock_Service.go b/core/files/fileuploader/mock_fileuploader/mock_Service.go deleted file mode 100644 index 327291132c..0000000000 --- a/core/files/fileuploader/mock_fileuploader/mock_Service.go +++ /dev/null @@ -1,178 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mock_fileuploader - -import ( - app "github.com/anyproto/any-sync/app" - fileuploader "github.com/anyproto/anytype-heart/core/files/fileuploader" - mock "github.com/stretchr/testify/mock" - - objectorigin "github.com/anyproto/anytype-heart/core/domain/objectorigin" -) - -// MockService is an autogenerated mock type for the Service type -type MockService struct { - mock.Mock -} - -type MockService_Expecter struct { - mock *mock.Mock -} - -func (_m *MockService) EXPECT() *MockService_Expecter { - return &MockService_Expecter{mock: &_m.Mock} -} - -// Init provides a mock function with given fields: a -func (_m *MockService) Init(a *app.App) error { - ret := _m.Called(a) - - if len(ret) == 0 { - panic("no return value specified for Init") - } - - var r0 error - if rf, ok := ret.Get(0).(func(*app.App) error); ok { - r0 = rf(a) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockService_Init_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Init' -type MockService_Init_Call struct { - *mock.Call -} - -// Init is a helper method to define mock.On call -// - a *app.App -func (_e *MockService_Expecter) Init(a interface{}) *MockService_Init_Call { - return &MockService_Init_Call{Call: _e.mock.On("Init", a)} -} - -func (_c *MockService_Init_Call) Run(run func(a *app.App)) *MockService_Init_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*app.App)) - }) - return _c -} - -func (_c *MockService_Init_Call) Return(err error) *MockService_Init_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockService_Init_Call) RunAndReturn(run func(*app.App) error) *MockService_Init_Call { - _c.Call.Return(run) - return _c -} - -// Name provides a mock function with given fields: -func (_m *MockService) Name() string { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Name") - } - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// MockService_Name_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Name' -type MockService_Name_Call struct { - *mock.Call -} - -// Name is a helper method to define mock.On call -func (_e *MockService_Expecter) Name() *MockService_Name_Call { - return &MockService_Name_Call{Call: _e.mock.On("Name")} -} - -func (_c *MockService_Name_Call) Run(run func()) *MockService_Name_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *MockService_Name_Call) Return(name string) *MockService_Name_Call { - _c.Call.Return(name) - return _c -} - -func (_c *MockService_Name_Call) RunAndReturn(run func() string) *MockService_Name_Call { - _c.Call.Return(run) - return _c -} - -// NewUploader provides a mock function with given fields: spaceId, origin -func (_m *MockService) NewUploader(spaceId string, origin objectorigin.ObjectOrigin) fileuploader.Uploader { - ret := _m.Called(spaceId, origin) - - if len(ret) == 0 { - panic("no return value specified for NewUploader") - } - - var r0 fileuploader.Uploader - if rf, ok := ret.Get(0).(func(string, objectorigin.ObjectOrigin) fileuploader.Uploader); ok { - r0 = rf(spaceId, origin) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(fileuploader.Uploader) - } - } - - return r0 -} - -// MockService_NewUploader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewUploader' -type MockService_NewUploader_Call struct { - *mock.Call -} - -// NewUploader is a helper method to define mock.On call -// - spaceId string -// - origin objectorigin.ObjectOrigin -func (_e *MockService_Expecter) NewUploader(spaceId interface{}, origin interface{}) *MockService_NewUploader_Call { - return &MockService_NewUploader_Call{Call: _e.mock.On("NewUploader", spaceId, origin)} -} - -func (_c *MockService_NewUploader_Call) Run(run func(spaceId string, origin objectorigin.ObjectOrigin)) *MockService_NewUploader_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(objectorigin.ObjectOrigin)) - }) - return _c -} - -func (_c *MockService_NewUploader_Call) Return(_a0 fileuploader.Uploader) *MockService_NewUploader_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockService_NewUploader_Call) RunAndReturn(run func(string, objectorigin.ObjectOrigin) fileuploader.Uploader) *MockService_NewUploader_Call { - _c.Call.Return(run) - return _c -} - -// NewMockService creates a new instance of MockService. 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 NewMockService(t interface { - mock.TestingT - Cleanup(func()) -}) *MockService { - mock := &MockService{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} From 90da4d28f1e35d5ae3cd7536b244bcef725b6d42 Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Tue, 8 Oct 2024 19:27:28 +0200 Subject: [PATCH 7/7] GO-3526: fix lint Signed-off-by: AnastasiaShemyakinskaya --- core/block/editor/file/file.go | 1 - 1 file changed, 1 deletion(-) diff --git a/core/block/editor/file/file.go b/core/block/editor/file/file.go index 050ab21077..f27fd326c5 100644 --- a/core/block/editor/file/file.go +++ b/core/block/editor/file/file.go @@ -484,7 +484,6 @@ func (dp *dropFilesProcess) Start(file smartblock.SmartBlock, targetId string, p dp.handleDragAndDropInDocument(file.RootId(), targetId, pos, rootDone, in) } wg.Wait() - return } func (dp *dropFilesProcess) handleDragAndDropInCollection(rootId string, droppedFiles []*dropFileEntry, rootDone chan error, in chan *dropFileInfo) {