From f64c185dd189f7767d3c9131f15b21da3fe63b48 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Mon, 18 Oct 2021 22:43:43 +0300 Subject: [PATCH] fix tests --- core/block/doc/service_test.go | 6 +++++ .../editor/smartblock/smartblock_test.go | 7 +----- core/history/history_test.go | 6 ++--- pkg/lib/localstore/objectstore/objects.go | 22 ++----------------- util/testMock/anytype.go | 7 +++++- 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/core/block/doc/service_test.go b/core/block/doc/service_test.go index fedc300d6..ae820a6e7 100644 --- a/core/block/doc/service_test.go +++ b/core/block/doc/service_test.go @@ -11,6 +11,8 @@ import ( "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/anytypeio/go-anytype-middleware/util/testMock" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -41,12 +43,16 @@ func TestService_ReportChange(t *testing.T) { } func TestService_WakeupLoop(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + dh := &testDocInfoHandler{ wakeupIds: make(chan string), } rb := recordsbatcher.New() a := new(app.App) a.Register(rb).Register(dh).Register(New()) + testMock.RegisterMockObjectStore(ctrl, a) require.NoError(t, a.Start()) defer a.Close() diff --git a/core/block/editor/smartblock/smartblock_test.go b/core/block/editor/smartblock/smartblock_test.go index 64d30a6a7..d4e3003b2 100644 --- a/core/block/editor/smartblock/smartblock_test.go +++ b/core/block/editor/smartblock/smartblock_test.go @@ -3,9 +3,6 @@ package smartblock import ( "testing" - "github.com/anytypeio/go-anytype-middleware/pkg/lib/bundle" - - "github.com/anytypeio/go-anytype-middleware/app" "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" @@ -88,8 +85,6 @@ func (fx *fixture) init(blocks []*model.Block) { doc := state.NewDoc(id, bm) fx.source.EXPECT().ReadDoc(gomock.Any(), false).Return(doc, nil) fx.source.EXPECT().Id().Return(id).AnyTimes() - ap := new(app.App) - ap.Register(restriction.New()) - err := fx.Init(&InitContext{Source: fx.source, App: ap}) + err := fx.Init(&InitContext{Source: fx.source, Restriction: restriction.New()}) require.NoError(fx.t, err) } diff --git a/core/history/history_test.go b/core/history/history_test.go index 44f4d5af0..784f9fa5e 100644 --- a/core/history/history_test.go +++ b/core/history/history_test.go @@ -1,16 +1,16 @@ package history import ( - "github.com/anytypeio/go-anytype-middleware/pkg/lib/threads" "testing" + "github.com/anytypeio/go-anytype-middleware/pkg/lib/threads" + "github.com/anytypeio/go-anytype-middleware/app" "github.com/anytypeio/go-anytype-middleware/app/testapp" "github.com/anytypeio/go-anytype-middleware/change" "github.com/anytypeio/go-anytype-middleware/core/block/editor/state" "github.com/anytypeio/go-anytype-middleware/pb" "github.com/anytypeio/go-anytype-middleware/util/testMock" - "github.com/anytypeio/go-anytype-middleware/util/testMock/mockMeta" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -60,7 +60,7 @@ func newFixture(t *testing.T) *fixture { a.EXPECT().ObjectStore().Return(nil).AnyTimes() a.EXPECT().ProfileID().AnyTimes() a.EXPECT().LocalProfile().AnyTimes() - mockMeta.RegisterMockMeta(ctrl, ta) + testMock.RegisterMockObjectStore(ctrl, ta) require.NoError(t, ta.Start()) return &fixture{ History: h, diff --git a/pkg/lib/localstore/objectstore/objects.go b/pkg/lib/localstore/objectstore/objects.go index 483ba7b16..06a0a4d91 100644 --- a/pkg/lib/localstore/objectstore/objects.go +++ b/pkg/lib/localstore/objectstore/objects.go @@ -185,20 +185,12 @@ func New() ObjectStore { return &dsObjectStore{} } -type DetailInjector interface { - SetLocalDetails(id string, st *types.Struct) -} - type SourceIdEncodedDetails interface { GetDetailsFromIdBasedSource(id string) (*types.Struct, error) } func (ls *dsObjectStore) Init(a *app.App) (err error) { ls.dsIface = a.MustComponent(datastore.CName).(datastore.Datastore) - meta := a.Component("meta") - if meta != nil { - ls.meta = meta.(DetailInjector) - } s := a.Component("source") if s != nil { ls.sourceService = a.MustComponent("source").(SourceIdEncodedDetails) @@ -330,8 +322,6 @@ type dsObjectStore struct { dsIface datastore.Datastore sourceService SourceIdEncodedDetails - meta DetailInjector // TODO: remove after we will migrate to the objectStore subscriptions - fts ftsearch.FTSearch // serializing page updates @@ -1548,14 +1538,10 @@ func (m *dsObjectStore) updateLinksBasedLocalRelation(txn ds.Txn, key bundle.Rel removedLinks, addedLinks := slice.DifferenceRemovedAdded(exLinks, links) setDetail := func(id string, val bool) error { - merged, err := m.injectObjectDetails(txn, id, &types.Struct{Fields: map[string]*types.Value{key.String(): pbtypes.Bool(val)}}) + _, err := m.injectObjectDetails(txn, id, &types.Struct{Fields: map[string]*types.Value{key.String(): pbtypes.Bool(val)}}) if err != nil { return err } - - // inject localDetails into the meta pubsub - m.meta.SetLocalDetails(id, merged) - return nil } @@ -1595,7 +1581,7 @@ func (m *dsObjectStore) updateWorkspaceLinks(txn ds.Txn, id string, exLinks, lin With("thread id", memberId). With("workspace id", id). Info("trying to inject object details") - merged, err := m.injectObjectDetails(txn, memberId, &types.Struct{ + _, err := m.injectObjectDetails(txn, memberId, &types.Struct{ Fields: map[string]*types.Value{ bundle.RelationKeyWorkspaceId.String(): tp, }, @@ -1608,10 +1594,6 @@ func (m *dsObjectStore) updateWorkspaceLinks(txn ds.Txn, id string, exLinks, lin Info("details injected with error: %v", err) return err } - - // inject localDetails into the meta pubsub - m.meta.SetLocalDetails(memberId, merged) - return nil } diff --git a/util/testMock/anytype.go b/util/testMock/anytype.go index 751f1fd1e..b9183ac31 100644 --- a/util/testMock/anytype.go +++ b/util/testMock/anytype.go @@ -4,12 +4,17 @@ package testMock import ( + "github.com/anytypeio/go-anytype-middleware/app" "github.com/anytypeio/go-anytype-middleware/app/testapp" "github.com/anytypeio/go-anytype-middleware/pkg/lib/core" "github.com/anytypeio/go-anytype-middleware/pkg/lib/localstore/objectstore" "github.com/golang/mock/gomock" ) +type App interface { + Register(component app.Component) *app.App +} + func RegisterMockAnytype(ctrl *gomock.Controller, ta *testapp.TestApp) *MockService { ms := NewMockService(ctrl) ms.EXPECT().Name().AnyTimes().Return(core.CName) @@ -20,7 +25,7 @@ func RegisterMockAnytype(ctrl *gomock.Controller, ta *testapp.TestApp) *MockServ return ms } -func RegisterMockObjectStore(ctrl *gomock.Controller, ta *testapp.TestApp) *MockObjectStore { +func RegisterMockObjectStore(ctrl *gomock.Controller, ta App) *MockObjectStore { ms := NewMockObjectStore(ctrl) ms.EXPECT().Name().AnyTimes().Return(objectstore.CName) ms.EXPECT().Init(gomock.Any()).AnyTimes()