From 0b1b8f452f51c66ffd33eb38de16a96f47bc03c8 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 25 Apr 2023 18:17:59 +0200 Subject: [PATCH] GO-501: Remove doc service as unused --- core/anytype/bootstrap.go | 2 - core/block/doc/service.go | 119 ------------------ core/block/doc/service_test.go | 91 -------------- core/block/editor.go | 6 - core/block/editor/breadcrumbs_test.go | 15 +-- core/block/editor/smartblock/smartblock.go | 31 +++-- .../editor/smartblock/smartblock_test.go | 7 +- .../editor/smartblock/smarttest/smarttest.go | 14 +-- core/block/service.go | 3 - core/indexer/indexer.go | 9 +- core/indexer/indexer_test.go | 13 +- util/testMock/mockDoc/doc.go | 18 --- 12 files changed, 38 insertions(+), 290 deletions(-) delete mode 100644 core/block/doc/service.go delete mode 100644 core/block/doc/service_test.go delete mode 100644 util/testMock/mockDoc/doc.go diff --git a/core/anytype/bootstrap.go b/core/anytype/bootstrap.go index bd471b30c..eedf1b283 100644 --- a/core/anytype/bootstrap.go +++ b/core/anytype/bootstrap.go @@ -18,7 +18,6 @@ import ( "github.com/anytypeio/go-anytype-middleware/core/block" "github.com/anytypeio/go-anytype-middleware/core/block/bookmark" decorator "github.com/anytypeio/go-anytype-middleware/core/block/bookmark/bookmarkimporter" - "github.com/anytypeio/go-anytype-middleware/core/block/doc" "github.com/anytypeio/go-anytype-middleware/core/block/editor" "github.com/anytypeio/go-anytype-middleware/core/block/export" importer "github.com/anytypeio/go-anytype-middleware/core/block/import" @@ -155,7 +154,6 @@ func Bootstrap(a *app.App, components ...app.Component) { Register(builtintemplate.New()). Register(status.New()). Register(block.New()). - Register(doc.New()). Register(indexer.New()). Register(history.New()). Register(gateway.New()). diff --git a/core/block/doc/service.go b/core/block/doc/service.go deleted file mode 100644 index a1ebaf6c4..000000000 --- a/core/block/doc/service.go +++ /dev/null @@ -1,119 +0,0 @@ -package doc - -import ( - "context" - "sync" - - "github.com/anytypeio/any-sync/app" - "github.com/anytypeio/any-sync/commonspace/object/treegetter" - - "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" - "github.com/anytypeio/go-anytype-middleware/core/recordsbatcher" - "github.com/anytypeio/go-anytype-middleware/pkg/lib/core" - "github.com/anytypeio/go-anytype-middleware/pkg/lib/logging" - "github.com/anytypeio/go-anytype-middleware/util/slice" -) - -const CName = "docService" - -var log = logging.Logger("anytype-mw-block-doc") - -func New() Service { - return &listener{} -} - -type DocInfo struct { - Id string - Links []string - FileHashes []string - Heads []string - Creator string - State *state.State -} - -type OnDocChangeCallback func(ctx context.Context, info DocInfo) error - -type Service interface { - OnWholeChange(cb OnDocChangeCallback) - ReportChange(ctx context.Context, info DocInfo) - WakeupIds(ids ...string) - - app.ComponentRunnable -} - -type docInfoHandler interface { - Wakeup(id string) (err error) -} - -type listener struct { - wholeCallbacks []OnDocChangeCallback - docInfoHandler docInfoHandler - records recordsbatcher.RecordsBatcher - - m sync.RWMutex -} - -func (l *listener) Init(a *app.App) (err error) { - l.docInfoHandler = a.MustComponent(treegetter.CName).(docInfoHandler) - l.records = a.MustComponent(recordsbatcher.CName).(recordsbatcher.RecordsBatcher) - return -} - -func (l *listener) Run(context.Context) (err error) { - go l.wakeupLoop() - return -} - -func (l *listener) Name() (name string) { - return CName -} - -func (l *listener) ReportChange(ctx context.Context, info DocInfo) { - l.m.RLock() - defer l.m.RUnlock() - for _, cb := range l.wholeCallbacks { - if err := cb(ctx, info); err != nil { - log.Errorf("state change callback error: %v", err) - } - } -} - -func (l *listener) OnWholeChange(cb OnDocChangeCallback) { - l.m.Lock() - defer l.m.Unlock() - l.wholeCallbacks = append(l.wholeCallbacks, cb) -} - -func (l *listener) WakeupIds(ids ...string) { - for _, id := range ids { - l.records.Add(core.ThreadRecordInfo{ThreadID: id}) - } -} - -func (l *listener) wakeupLoop() { - var buf = make([]interface{}, 50) - var idsToWakeup []string - for { - n := l.records.Read(buf) - if n == 0 { - return - } - idsToWakeup = idsToWakeup[:0] - for _, rec := range buf[:n] { - if val, ok := rec.(core.ThreadRecordInfo); !ok { - log.Errorf("doc listner got unknown type %t", rec) - } else { - if slice.FindPos(idsToWakeup, val.ThreadID) == -1 { - idsToWakeup = append(idsToWakeup, val.ThreadID) - if err := l.docInfoHandler.Wakeup(val.ThreadID); err != nil { - log.With("thread", val.ThreadID).Errorf("can't wakeup thread") - } - } - } - } - } -} - -func (l *listener) Close(ctx context.Context) (err error) { - return -} diff --git a/core/block/doc/service_test.go b/core/block/doc/service_test.go deleted file mode 100644 index c0a47d744..000000000 --- a/core/block/doc/service_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package doc - -import ( - "context" - "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/treegetter" - "testing" - "time" - - "github.com/anytypeio/any-sync/app" - "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" - "github.com/anytypeio/go-anytype-middleware/core/block/simple" - "github.com/anytypeio/go-anytype-middleware/core/recordsbatcher" - "github.com/anytypeio/go-anytype-middleware/pkg/lib/core" - "github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestService_ReportChange(t *testing.T) { - l := New() - defer l.Close(context.Background()) - - var calls int - - var expId = "testId" - var expState = state.NewDoc("testId", map[string]simple.Block{ - "testId": simple.New(&model.Block{Id: "testId"}), - }).(*state.State) - var expCount = 2 - for i := 0; i < expCount; i++ { - l.OnWholeChange(func(ctx context.Context, info DocInfo) error { - assert.Equal(t, expId, info.Id) - assert.Equal(t, expState.StringDebug(), info.State.StringDebug()) - calls++ - return nil - }) - } - - l.ReportChange(context.Background(), DocInfo{Id: expId, State: expState}) - - assert.Equal(t, expCount, calls) -} - -func TestService_WakeupLoop(t *testing.T) { - dh := &testDocInfoHandler{ - wakeupIds: make(chan string), - } - rb := recordsbatcher.New() - a := new(app.App) - a.Register(rb).Register(dh).Register(New()) - require.NoError(t, a.Start(context.Background())) - defer a.Close(context.Background()) - - recId := func(id string) core.ThreadRecordInfo { - return core.ThreadRecordInfo{ThreadID: id} - } - - require.NoError(t, rb.Add(recId("1"), recId("2"), recId("2"), recId("1"), recId("3"))) - - var result []string - for i := 0; i < 3; i++ { - select { - case id := <-dh.wakeupIds: - result = append(result, id) - case <-time.After(time.Second / 4): - t.Errorf("timeout") - } - } - assert.Equal(t, []string{"1", "2", "3"}, result) -} - -type testDocInfoHandler struct { - wakeupIds chan string -} - -func (t *testDocInfoHandler) GetDocInfo(ctx context.Context, id string) (info DocInfo, err error) { - return -} - -func (t *testDocInfoHandler) Wakeup(id string) (err error) { - t.wakeupIds <- id - return -} - -func (t *testDocInfoHandler) Init(a *app.App) (err error) { - return nil -} - -func (t *testDocInfoHandler) Name() (name string) { - return treegetter.CName -} diff --git a/core/block/editor.go b/core/block/editor.go index f97241c66..23818cf4d 100644 --- a/core/block/editor.go +++ b/core/block/editor.go @@ -589,12 +589,6 @@ func (s *Service) AddRelationBlock(ctx *session.Context, req pb.RpcBlockRelation }) } -func (s *Service) Wakeup(id string) (err error) { - return s.Do(id, func(b smartblock.SmartBlock) error { - return nil - }) -} - func (s *Service) GetRelations(objectId string) (relations []*model.Relation, err error) { err = s.Do(objectId, func(b smartblock.SmartBlock) error { relations = b.Relations(nil).Models() diff --git a/core/block/editor/breadcrumbs_test.go b/core/block/editor/breadcrumbs_test.go index 0ea3eac17..ae70a00e3 100644 --- a/core/block/editor/breadcrumbs_test.go +++ b/core/block/editor/breadcrumbs_test.go @@ -2,18 +2,19 @@ package editor import ( "context" + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/anytypeio/go-anytype-middleware/app/testapp" "github.com/anytypeio/go-anytype-middleware/core/block/editor/smartblock" "github.com/anytypeio/go-anytype-middleware/core/block/restriction" "github.com/anytypeio/go-anytype-middleware/core/block/source" "github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model" "github.com/anytypeio/go-anytype-middleware/util/testMock" - "github.com/anytypeio/go-anytype-middleware/util/testMock/mockDoc" "github.com/anytypeio/go-anytype-middleware/util/testMock/mockRelation" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "testing" ) func TestBreadcrumbs_Init(t *testing.T) { @@ -36,7 +37,6 @@ func TestBreadcrumbs_SetCrumbs(t *testing.T) { fx := newFixture(t) defer fx.Finish() fx.expectDerivedDetails() - fx.mockDoc.EXPECT().ReportChange(gomock.Any(), gomock.Any()).AnyTimes() b := NewBreadcrumbs() err := b.Init(&smartblock.InitContext{ @@ -60,7 +60,6 @@ func newFixture(t *testing.T) *fixture { t: t, } fx.mockStore = testMock.RegisterMockObjectStore(fx.ctrl, fx.app) - fx.mockDoc = mockDoc.RegisterMockDoc(fx.ctrl, fx.app) fx.mockAnytype = testMock.RegisterMockAnytype(fx.ctrl, fx.app) fx.app.Register(restriction.New()) mockRelation.RegisterMockRelation(fx.ctrl, fx.app) @@ -74,7 +73,6 @@ type fixture struct { ctrl *gomock.Controller app *testapp.TestApp mockStore *testMock.MockObjectStore - mockDoc *mockDoc.MockService mockAnytype *testMock.MockService } @@ -82,7 +80,6 @@ func (fx *fixture) expectDerivedDetails() { fx.mockStore.EXPECT().GetDetails(gomock.Any()).Return(&model.ObjectDetails{}, nil) fx.mockStore.EXPECT().GetPendingLocalDetails(gomock.Any()).Return(&model.ObjectDetails{}, nil) fx.mockStore.EXPECT().UpdatePendingLocalDetails(gomock.Any(), gomock.Any()) - fx.mockDoc.EXPECT().ReportChange(gomock.Any(), gomock.Any()) } func (fx *fixture) Finish() { diff --git a/core/block/editor/smartblock/smartblock.go b/core/block/editor/smartblock/smartblock.go index 86a12a7e7..b5e48670f 100644 --- a/core/block/editor/smartblock/smartblock.go +++ b/core/block/editor/smartblock/smartblock.go @@ -13,7 +13,6 @@ import ( "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" "github.com/gogo/protobuf/types" - "github.com/anytypeio/go-anytype-middleware/core/block/doc" "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" "github.com/anytypeio/go-anytype-middleware/core/block/editor/template" "github.com/anytypeio/go-anytype-middleware/core/block/restriction" @@ -119,7 +118,7 @@ type SmartBlock interface { EnabledRelationAsDependentObjects() AddHook(f HookCallback, events ...Hook) CheckSubscriptions() (changed bool) - GetDocInfo() (doc.DocInfo, error) + GetDocInfo() DocInfo Restrictions() restriction.Restrictions SetRestrictions(r restriction.Restrictions) ObjectClose() @@ -131,6 +130,15 @@ type SmartBlock interface { sync.Locker } +type DocInfo struct { + Id string + Links []string + FileHashes []string + Heads []string + Creator string + State *state.State +} + type InitContext struct { Source source.Source ObjectTypeUrls []string @@ -138,7 +146,6 @@ type InitContext struct { State *state.State Relations []*model.Relation Restriction restriction.Service - Doc doc.Service ObjectStore objectstore.ObjectStore Ctx context.Context ObjectTree objecttree.ObjectTree @@ -156,7 +163,7 @@ type Locker interface { } type Indexer interface { - Index(ctx context.Context, info doc.DocInfo) error + Index(ctx context.Context, info DocInfo) error } type smartBlock struct { @@ -699,7 +706,7 @@ func (sb *smartBlock) Apply(s *state.State, flags ...ApplyFlag) (err error) { } } - sb.reportChange(st) + sb.runIndexer(st) if hasDepIds(sb.GetRelationLinks(), &act) { sb.CheckSubscriptions() @@ -1136,7 +1143,7 @@ func (sb *smartBlock) StateAppend(f func(d state.Doc) (s *state.State, changes [ if hasDepIds(sb.GetRelationLinks(), &act) { sb.CheckSubscriptions() } - sb.reportChange(s) + sb.runIndexer(s) sb.execHooks(HookAfterApply, ApplyInfo{State: s, Events: msgs, Changes: changes}) return nil @@ -1166,7 +1173,7 @@ func (sb *smartBlock) StateRebuild(d state.Doc) (err error) { } sb.storeFileKeys(d) sb.CheckSubscriptions() - sb.reportChange(sb.Doc.(*state.State)) + sb.runIndexer(sb.Doc.(*state.State)) sb.execHooks(HookAfterApply, ApplyInfo{State: sb.Doc.(*state.State), Events: msgs, Changes: d.(*state.State).GetChanges()}) return nil } @@ -1317,11 +1324,11 @@ func (sb *smartBlock) execHooks(event Hook, info ApplyInfo) (err error) { return } -func (sb *smartBlock) GetDocInfo() (doc.DocInfo, error) { - return sb.getDocInfo(sb.NewState()), nil +func (sb *smartBlock) GetDocInfo() DocInfo { + return sb.getDocInfo(sb.NewState()) } -func (sb *smartBlock) getDocInfo(st *state.State) doc.DocInfo { +func (sb *smartBlock) getDocInfo(st *state.State) DocInfo { fileHashes := st.GetAllFileHashes(sb.FileRelationKeys(st)) creator := pbtypes.GetString(st.Details(), bundle.RelationKeyCreator.String()) if creator == "" { @@ -1334,7 +1341,7 @@ func (sb *smartBlock) getDocInfo(st *state.State) doc.DocInfo { // so links will have this order // 1. Simple blocks: links, mentions in the text // 2. Relations(format==Object) - return doc.DocInfo{ + return DocInfo{ Id: sb.Id(), Links: links, Heads: sb.source.Heads(), @@ -1344,7 +1351,7 @@ func (sb *smartBlock) getDocInfo(st *state.State) doc.DocInfo { } } -func (sb *smartBlock) reportChange(s *state.State) { +func (sb *smartBlock) runIndexer(s *state.State) { docInfo := sb.getDocInfo(s) if err := sb.indexer.Index(context.TODO(), docInfo); err != nil { log.Errorf("index object %s error: %s", sb.Id(), err) diff --git a/core/block/editor/smartblock/smartblock_test.go b/core/block/editor/smartblock/smartblock_test.go index 4fbbf82cd..81e06587b 100644 --- a/core/block/editor/smartblock/smartblock_test.go +++ b/core/block/editor/smartblock/smartblock_test.go @@ -4,12 +4,12 @@ import ( "context" "testing" + "github.com/anytypeio/any-sync/app" "github.com/gogo/protobuf/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/anytypeio/any-sync/app" "github.com/anytypeio/go-anytype-middleware/app/testapp" "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" "github.com/anytypeio/go-anytype-middleware/core/block/restriction" @@ -20,7 +20,6 @@ import ( "github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model" "github.com/anytypeio/go-anytype-middleware/util/pbtypes" "github.com/anytypeio/go-anytype-middleware/util/testMock" - "github.com/anytypeio/go-anytype-middleware/util/testMock/mockDoc" "github.com/anytypeio/go-anytype-middleware/util/testMock/mockRelation" "github.com/anytypeio/go-anytype-middleware/util/testMock/mockSource" @@ -99,7 +98,6 @@ type fixture struct { source *mockSource.MockSource snapshot *testMock.MockSmartBlockSnapshot store *testMock.MockObjectStore - md *mockDoc.MockService SmartBlock } @@ -119,7 +117,6 @@ func newFixture(t *testing.T) *fixture { a := testapp.New() a.Register(store). Register(restriction.New()) - md := mockDoc.RegisterMockDoc(ctrl, a) mockRelation.RegisterMockRelation(ctrl, a) return &fixture{ @@ -129,7 +126,6 @@ func newFixture(t *testing.T) *fixture { store: store, app: a.App, source: source, - md: md, } } @@ -151,7 +147,6 @@ func (fx *fixture) init(blocks []*model.Block) { Details: &types.Struct{Fields: map[string]*types.Value{}}, }, nil) - fx.md.EXPECT().ReportChange(gomock.Any(), gomock.Any()).AnyTimes() fx.store.EXPECT().GetPendingLocalDetails(id).Return(&model.ObjectDetails{ Details: &types.Struct{Fields: map[string]*types.Value{}}, }, nil) diff --git a/core/block/editor/smartblock/smarttest/smarttest.go b/core/block/editor/smartblock/smarttest/smarttest.go index 9525c51a0..79929feb5 100644 --- a/core/block/editor/smartblock/smarttest/smarttest.go +++ b/core/block/editor/smartblock/smarttest/smarttest.go @@ -1,24 +1,24 @@ package smarttest import ( - "github.com/anytypeio/any-sync/app" - "github.com/anytypeio/go-anytype-middleware/core/relation" - "github.com/anytypeio/go-anytype-middleware/core/relation/relationutils" "sync" - "github.com/anytypeio/go-anytype-middleware/core/block/doc" + "github.com/anytypeio/any-sync/app" + "github.com/gogo/protobuf/types" + "github.com/anytypeio/go-anytype-middleware/core/block/editor/smartblock" "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" "github.com/anytypeio/go-anytype-middleware/core/block/restriction" "github.com/anytypeio/go-anytype-middleware/core/block/simple" "github.com/anytypeio/go-anytype-middleware/core/block/undo" + "github.com/anytypeio/go-anytype-middleware/core/relation" + "github.com/anytypeio/go-anytype-middleware/core/relation/relationutils" "github.com/anytypeio/go-anytype-middleware/core/session" "github.com/anytypeio/go-anytype-middleware/pb" "github.com/anytypeio/go-anytype-middleware/pkg/lib/core" "github.com/anytypeio/go-anytype-middleware/pkg/lib/localstore/objectstore" "github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model" "github.com/anytypeio/go-anytype-middleware/util/testMock" - "github.com/gogo/protobuf/types" ) func New(id string) *SmartTest { @@ -99,8 +99,8 @@ func (st *SmartTest) Restrictions() restriction.Restrictions { return st.TestRestrictions } -func (st *SmartTest) GetDocInfo() (doc.DocInfo, error) { - return doc.DocInfo{ +func (st *SmartTest) GetDocInfo() (DocInfo, error) { + return DocInfo{ Id: st.Id(), }, nil } diff --git a/core/block/service.go b/core/block/service.go index 51237d717..4bb5b310c 100644 --- a/core/block/service.go +++ b/core/block/service.go @@ -18,7 +18,6 @@ import ( "github.com/ipfs/go-datastore/query" bookmarksvc "github.com/anytypeio/go-anytype-middleware/core/block/bookmark" - "github.com/anytypeio/go-anytype-middleware/core/block/doc" "github.com/anytypeio/go-anytype-middleware/core/block/editor" "github.com/anytypeio/go-anytype-middleware/core/block/editor/basic" "github.com/anytypeio/go-anytype-middleware/core/block/editor/bookmark" @@ -122,7 +121,6 @@ type Service struct { closed bool linkPreview linkpreview.LinkPreview process process.Service - doc doc.Service app *app.App source source.Service objectStore objectstore.ObjectStore @@ -150,7 +148,6 @@ func (s *Service) Init(a *app.App) (err error) { s.process = a.MustComponent(process.CName).(process.Service) s.sendEvent = a.MustComponent(event.CName).(event.Sender).Send s.source = a.MustComponent(source.CName).(source.Service) - s.doc = a.MustComponent(doc.CName).(doc.Service) s.objectStore = a.MustComponent(objectstore.CName).(objectstore.ObjectStore) s.restriction = a.MustComponent(restriction.CName).(restriction.Service) s.bookmark = a.MustComponent("bookmark-importer").(bookmarksvc.Service) diff --git a/core/indexer/indexer.go b/core/indexer/indexer.go index 4c50b49e1..dbe3930a8 100644 --- a/core/indexer/indexer.go +++ b/core/indexer/indexer.go @@ -16,7 +16,6 @@ import ( "github.com/anytypeio/go-anytype-middleware/core/anytype/config" "github.com/anytypeio/go-anytype-middleware/core/block" - "github.com/anytypeio/go-anytype-middleware/core/block/doc" smartblock2 "github.com/anytypeio/go-anytype-middleware/core/block/editor/smartblock" "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" "github.com/anytypeio/go-anytype-middleware/core/block/editor/template" @@ -213,7 +212,7 @@ func (i *indexer) Close(ctx context.Context) (err error) { return nil } -func (i *indexer) Index(ctx context.Context, info doc.DocInfo) error { +func (i *indexer) Index(ctx context.Context, info smartblock2.DocInfo) error { startTime := time.Now() sbType, err := i.typeProvider.Type(info.Id) if err != nil { @@ -812,10 +811,10 @@ func (i *indexer) reindexIdsIgnoreErr(ctx context.Context, indexRemoved bool, id return } -func (i *indexer) getObjectInfo(ctx context.Context, id string) (info doc.DocInfo, err error) { +func (i *indexer) getObjectInfo(ctx context.Context, id string) (info smartblock2.DocInfo, err error) { err = block.DoWithContext(ctx, i.picker, id, func(sb smartblock2.SmartBlock) error { - info, err = sb.GetDocInfo() - return err + info = sb.GetDocInfo() + return nil }) return } diff --git a/core/indexer/indexer_test.go b/core/indexer/indexer_test.go index 391df53fb..821374cf2 100644 --- a/core/indexer/indexer_test.go +++ b/core/indexer/indexer_test.go @@ -7,15 +7,13 @@ import ( "os" "testing" + "github.com/anytypeio/any-sync/app" "github.com/gogo/protobuf/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/anytypeio/any-sync/app" "github.com/anytypeio/go-anytype-middleware/app/testapp" "github.com/anytypeio/go-anytype-middleware/core/anytype/config" - "github.com/anytypeio/go-anytype-middleware/core/block/doc" - "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" "github.com/anytypeio/go-anytype-middleware/core/block/source" "github.com/anytypeio/go-anytype-middleware/core/indexer" "github.com/anytypeio/go-anytype-middleware/core/recordsbatcher" @@ -31,7 +29,6 @@ import ( "github.com/anytypeio/go-anytype-middleware/util/pbtypes" "github.com/anytypeio/go-anytype-middleware/util/testMock" "github.com/anytypeio/go-anytype-middleware/util/testMock/mockBuiltinTemplate" - "github.com/anytypeio/go-anytype-middleware/util/testMock/mockDoc" "github.com/anytypeio/go-anytype-middleware/util/testMock/mockRelation" "github.com/anytypeio/go-anytype-middleware/util/testMock/mockStatus" ) @@ -57,16 +54,9 @@ func newFixture(t *testing.T) *fixture { } fx.anytype = testMock.RegisterMockAnytype(fx.ctrl, ta) - fx.docService = mockDoc.NewMockService(fx.ctrl) - fx.docService.EXPECT().Name().AnyTimes().Return(doc.CName) - fx.docService.EXPECT().Init(gomock.Any()) - fx.docService.EXPECT().Run(context.Background()) fx.anytype.EXPECT().PredefinedBlocks().Times(2) - fx.docService.EXPECT().Close().AnyTimes() fx.objectStore = testMock.RegisterMockObjectStore(fx.ctrl, ta) - fx.docService.EXPECT().GetDocInfo(gomock.Any(), gomock.Any()).Return(doc.DocInfo{State: state.NewDoc("", nil).(*state.State)}, nil).AnyTimes() - fx.docService.EXPECT().OnWholeChange(gomock.Any()) fx.objectStore.EXPECT().GetDetails(addr.AnytypeProfileId) fx.objectStore.EXPECT().AddToIndexQueue(addr.AnytypeProfileId) @@ -127,7 +117,6 @@ type fixture struct { ctrl *gomock.Controller anytype *testMock.MockService objectStore *testMock.MockObjectStore - docService *mockDoc.MockService ch chan core.SmartblockRecordWithThreadID rb recordsbatcher.RecordsBatcher ta *testapp.TestApp diff --git a/util/testMock/mockDoc/doc.go b/util/testMock/mockDoc/doc.go deleted file mode 100644 index 63fbbd8ee..000000000 --- a/util/testMock/mockDoc/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:generate mockgen -package mockDoc -destination doc_mock.go github.com/anytypeio/go-anytype-middleware/core/block/doc Service -package mockDoc - -import ( - "github.com/anytypeio/go-anytype-middleware/app/testapp" - "github.com/anytypeio/go-anytype-middleware/core/block/doc" - "github.com/golang/mock/gomock" -) - -func RegisterMockDoc(ctrl *gomock.Controller, ta *testapp.TestApp) *MockService { - ms := NewMockService(ctrl) - ms.EXPECT().Name().AnyTimes().Return(doc.CName) - ms.EXPECT().Init(gomock.Any()).AnyTimes() - ms.EXPECT().Run(gomock.Any()).AnyTimes() - ms.EXPECT().Close().AnyTimes() - ta.Register(ms) - return ms -}