mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
fix tests
This commit is contained in:
parent
5aed529617
commit
f64c185dd1
5 changed files with 18 additions and 30 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue