1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 17:44:59 +09:00

GO-2548 wip

This commit is contained in:
mcrakhman 2023-12-19 15:34:51 +01:00
parent 16bfe62192
commit a690b42248
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
7 changed files with 1314 additions and 131 deletions

View file

@ -1,133 +1,84 @@
package space
//import (
// "context"
// "testing"
//
// "github.com/anyproto/any-sync/app"
// "github.com/anyproto/any-sync/commonspace/mock_commonspace"
// "github.com/anyproto/any-sync/commonspace/object/treesyncer/mock_treesyncer"
// "github.com/stretchr/testify/mock"
// "github.com/stretchr/testify/require"
// "go.uber.org/mock/gomock"
//
// "github.com/anyproto/anytype-heart/core/block/object/objectcache/mock_objectcache"
// "github.com/anyproto/anytype-heart/core/domain"
// "github.com/anyproto/anytype-heart/space/internal/techspace/mock_techspace"
// "github.com/anyproto/anytype-heart/space/spacecore"
// "github.com/anyproto/anytype-heart/space/spacecore/mock_spacecore"
// "github.com/anyproto/anytype-heart/space/spaceinfo"
// "github.com/anyproto/anytype-heart/tests/testutil"
//)
//
//var ctx = context.Background()
//
//const (
// testPersonalSpaceID = "personal.id"
//)
//
//// TODO Revive tests
//func xTestService_Init(t *testing.T) {
// t.Run("existing account", func(t *testing.T) {
// fx := newFixture(t, false)
// defer fx.finish(t)
// })
// t.Run("new account", func(t *testing.T) {
// fx := newFixture(t, true)
// defer fx.finish(t)
// })
//
//}
//
//type indexerStub struct {
//}
//
//func (i *indexerStub) ReindexMarketplaceSpace(space Space) error {
// return nil
//}
//
//func (i *indexerStub) ReindexSpace(space Space) error {
// return nil
//}
//
//func (i *indexerStub) Init(a *app.App) (err error) {
// return nil
//}
//
//func (i *indexerStub) Name() (name string) {
// return "indexerStub"
//}
//
//func newFixture(t *testing.T, newAccount bool) *fixture {
// ctrl := gomock.NewController(t)
// fx := &fixture{
// service: New().(*service),
// a: new(app.App),
// ctrl: ctrl,
// objectCache: mock_objectcache.NewMockCache(t),
// spaceCore: mock_spacecore.NewMockSpaceCoreService(t),
// installer: NewMockbundledObjectsInstaller(t),
// isNewAccount: NewMockisNewAccount(t),
// techSpace: mock_techspace.NewMockTechSpace(t),
// personalSpace: mock_commonspace.NewMockSpace(ctrl),
// }
// fx.a.Register(&indexerStub{}).
// Register(testutil.PrepareMock(ctx, fx.a, fx.spaceCore)).
// Register(testutil.PrepareMock(ctx, fx.a, fx.installer)).
// Register(testutil.PrepareMock(ctx, fx.a, fx.isNewAccount)).
// Register(fx.service)
//
// fx.isNewAccount.EXPECT().IsNewAccount().Return(newAccount)
// fx.personalSpace.EXPECT().Id().AnyTimes().Return(testPersonalSpaceID)
//
// fx.expectRun(newAccount)
//
// require.NoError(t, fx.a.Start(ctx))
//
// return fx
//}
//
//type fixture struct {
// *service
// a *app.App
// objectCache *mock_objectcache.MockCache
// spaceCore *mock_spacecore.MockSpaceCoreService
// installer *MockbundledObjectsInstaller
// ctrl *gomock.Controller
// isNewAccount *MockisNewAccount
// techSpace *mock_techspace.MockTechSpace
// personalSpace *mock_commonspace.MockSpace
//}
//
//func (fx *fixture) expectRun(newAccount bool) {
// fx.spaceCore.EXPECT().DeriveID(mock.Anything, spacecore.SpaceType).Return(testPersonalSpaceID, nil)
//
// if newAccount {
// fx.spaceCore.EXPECT().Derive(mock.Anything, spacecore.SpaceType).Return(&spacecore.AnySpace{Space: fx.personalSpace}, nil)
// // fx.objectCache.EXPECT().DeriveTreeObject(mock.Anything, testPersonalSpaceID, mock.Anything).Return(nil, nil)
// fx.techSpace.EXPECT().SpaceViewCreate(mock.Anything, testPersonalSpaceID, nil).Return(nil)
// }
// // startLoad
// fx.techSpace.EXPECT().SpaceViewExists(mock.Anything, testPersonalSpaceID).Return(true, nil)
// fx.techSpace.EXPECT().SetLocalInfo(mock.Anything, mock.Anything).Return(nil)
// // wait load
// fx.spaceCore.EXPECT().Get(mock.Anything, testPersonalSpaceID).Return(&spacecore.AnySpace{Space: fx.personalSpace}, nil)
// fx.techSpace.EXPECT().SetLocalInfo(mock.Anything, spaceinfo.SpaceLocalInfo{
// SpaceID: testPersonalSpaceID,
// LocalStatus: spaceinfo.LocalStatusOk,
// RemoteStatus: spaceinfo.RemoteStatusUnknown,
// }).Return(nil)
//
// // space init
// // fx.objectCache.EXPECT().DeriveObjectID(mock.Anything, testPersonalSpaceID, mock.Anything).Return("derived", nil)
// fx.objectCache.EXPECT().GetObject(mock.Anything, domain.FullID{ObjectID: "derived", SpaceID: testPersonalSpaceID}).Return(nil, nil)
// fx.installer.EXPECT().InstallBundledObjects(mock.Anything, testPersonalSpaceID, mock.Anything).Return(nil, nil, nil)
// ts := mock_treesyncer.NewMockTreeSyncer(fx.ctrl)
// ts.EXPECT().StartSync()
// fx.personalSpace.EXPECT().TreeSyncer().Return(ts)
//}
//
//func (fx *fixture) finish(t *testing.T) {
// require.NoError(t, fx.a.Close(ctx))
// fx.ctrl.Finish()
//}
import (
"context"
"testing"
"github.com/anyproto/any-sync/accountservice/mock_accountservice"
"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/coordinator/coordinatorclient/mock_coordinatorclient"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"github.com/anyproto/anytype-heart/space/spacecore/mock_spacecore"
"github.com/anyproto/anytype-heart/space/spacefactory/mock_spacefactory"
"github.com/anyproto/anytype-heart/tests/testutil"
)
var ctx = context.Background()
const (
testPersonalSpaceID = "personal.12345"
)
// TODO Revive tests
func TestService_Init(t *testing.T) {
t.Run("existing account", func(t *testing.T) {
fx := newFixture(t, false)
defer fx.finish(t)
})
t.Run("new account", func(t *testing.T) {
fx := newFixture(t, true)
defer fx.finish(t)
})
}
func newFixture(t *testing.T, newAccount bool) *fixture {
ctrl := gomock.NewController(t)
fx := &fixture{
service: New().(*service),
a: new(app.App),
ctrl: ctrl,
spaceCore: mock_spacecore.NewMockSpaceCoreService(t),
accountService: mock_accountservice.NewMockService(ctrl),
coordClient: mock_coordinatorclient.NewMockCoordinatorClient(ctrl),
factory: mock_spacefactory.NewMockSpaceFactory(t),
isNewAccount: NewMockisNewAccount(t),
}
fx.a.Register(testutil.PrepareMock(ctx, fx.a, fx.spaceCore)).
Register(testutil.PrepareMock(ctx, fx.a, fx.coordClient)).
Register(testutil.PrepareMock(ctx, fx.a, fx.accountService)).
Register(testutil.PrepareMock(ctx, fx.a, fx.isNewAccount)).
Register(testutil.PrepareMock(ctx, fx.a, fx.factory)).
Register(fx.service)
fx.isNewAccount.EXPECT().IsNewAccount().Return(newAccount)
fx.spaceCore.EXPECT().DeriveID(mock.Anything, mock.Anything).Return(testPersonalSpaceID, nil)
fx.expectRun(newAccount)
require.NoError(t, fx.a.Start(ctx))
return fx
}
type fixture struct {
*service
a *app.App
factory *mock_spacefactory.MockSpaceFactory
spaceCore *mock_spacecore.MockSpaceCoreService
accountService *mock_accountservice.MockService
coordClient *mock_coordinatorclient.MockCoordinatorClient
ctrl *gomock.Controller
isNewAccount *MockisNewAccount
}
func (fx *fixture) expectRun(newAccount bool) {
return
}
func (fx *fixture) finish(t *testing.T) {
require.NoError(t, fx.a.Close(ctx))
fx.ctrl.Finish()
}