diff --git a/core/block/collection/service_test.go b/core/block/collection/service_test.go index b8b2b0f1a..3b889072a 100644 --- a/core/block/collection/service_test.go +++ b/core/block/collection/service_test.go @@ -13,7 +13,6 @@ import ( "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/relation/mock_relation" - "github.com/anyproto/anytype-heart/core/session" "github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore/mock_objectstore" ) diff --git a/core/subscription/fixture_test.go b/core/subscription/fixture_test.go index f92b38059..2d240220e 100644 --- a/core/subscription/fixture_test.go +++ b/core/subscription/fixture_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/anyproto/any-sync/app" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -15,7 +14,9 @@ import ( "github.com/anyproto/anytype-heart/core/event/mock_event" "github.com/anyproto/anytype-heart/pb" "github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore" + "github.com/anyproto/anytype-heart/space/typeprovider/mock_typeprovider" "github.com/anyproto/anytype-heart/util/testMock" + "go.uber.org/mock/gomock" ) type collectionServiceMock struct { @@ -29,13 +30,27 @@ func (c *collectionServiceMock) SubscribeForCollection(collectionID string, subs func (c *collectionServiceMock) UnsubscribeFromCollection(collectionID string, subscriptionID string) { } +type fixture struct { + Service + a *app.App + ctrl *gomock.Controller + store *testMock.MockObjectStore + sender *mock_event.MockSender + events []*pb.Event +} + func newFixture(t *testing.T) *fixture { ctrl := gomock.NewController(t) a := new(app.App) testMock.RegisterMockObjectStore(ctrl, a) testMock.RegisterMockKanban(ctrl, a) + a.Register(&collectionServiceMock{}) + sbtProvider := mock_typeprovider.NewMockSmartBlockTypeProvider(t) + sbtProvider.EXPECT().Name().Return("smartBlockTypeProvider") + sbtProvider.EXPECT().Init(mock.Anything).Return(nil) + a.Register(sbtProvider) fx := &fixture{ - Service: New(&collectionServiceMock{}, nil), + Service: New(), a: a, ctrl: ctrl, store: a.MustComponent(objectstore.CName).(*testMock.MockObjectStore), @@ -55,13 +70,13 @@ func newFixture(t *testing.T) *fixture { return fx } -type fixture struct { +type fixtureRealStore struct { Service a *app.App ctrl *gomock.Controller - store *testMock.MockObjectStore + store *objectstore.StoreFixture sender *mock_event.MockSender - events []*pb.Event + events []pb.IsEventMessageValue } func newFixtureWithRealObjectStore(t *testing.T) *fixtureRealStore { @@ -70,8 +85,13 @@ func newFixtureWithRealObjectStore(t *testing.T) *fixtureRealStore { store := objectstore.NewStoreFixture(t) a.Register(store) testMock.RegisterMockKanban(ctrl, a) + a.Register(&collectionServiceMock{}) + sbtProvider := mock_typeprovider.NewMockSmartBlockTypeProvider(t) + sbtProvider.EXPECT().Name().Return("smartBlockTypeProvider") + sbtProvider.EXPECT().Init(mock.Anything).Return(nil) + a.Register(sbtProvider) fx := &fixtureRealStore{ - Service: New(&collectionServiceMock{}, nil), + Service: New(), a: a, ctrl: ctrl, store: store, @@ -92,15 +112,6 @@ func newFixtureWithRealObjectStore(t *testing.T) *fixtureRealStore { return fx } -type fixtureRealStore struct { - Service - a *app.App - ctrl *gomock.Controller - store *objectstore.StoreFixture - sender *mock_event.MockSender - events []pb.IsEventMessageValue -} - func (fx *fixtureRealStore) waitEvents(t *testing.T, ev ...pb.IsEventMessageValue) { timeout := time.NewTimer(1 * time.Second) ticker := time.NewTicker(1 * time.Millisecond) diff --git a/core/subscription/service_test.go b/core/subscription/service_test.go index c50c8b9b7..a2f3447f5 100644 --- a/core/subscription/service_test.go +++ b/core/subscription/service_test.go @@ -4,22 +4,17 @@ import ( "context" "testing" - "github.com/gogo/protobuf/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" - "github.com/anyproto/anytype-heart/core/event" - "github.com/anyproto/anytype-heart/core/event/mock_event" - "github.com/anyproto/anytype-heart/core/session" + "github.com/anyproto/any-sync/app" "github.com/anyproto/anytype-heart/pb" "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/database" "github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/space/typeprovider/mock_typeprovider" "github.com/anyproto/anytype-heart/util/pbtypes" - "github.com/anyproto/anytype-heart/util/testMock" - "github.com/stretchr/testify/mock" + "github.com/gogo/protobuf/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) func TestService_Search(t *testing.T) { @@ -353,6 +348,8 @@ func TestNestedSubscription(t *testing.T) { }, }) require.NoError(t, err) + }) +} func (c *collectionServiceMock) Name() string { return "collectionService" @@ -360,49 +357,6 @@ func (c *collectionServiceMock) Name() string { func (c *collectionServiceMock) Init(a *app.App) error { return nil } -func newFixture(t *testing.T) *fixture { - ctrl := gomock.NewController(t) - a := new(app.App) - testMock.RegisterMockObjectStore(ctrl, a) - testMock.RegisterMockKanban(ctrl, a) - fx := &fixture{ - Service: New(), - a: a, - ctrl: ctrl, - store: a.MustComponent(objectstore.CName).(*testMock.MockObjectStore), - } - sender := mock_event.NewMockSender(t) - sender.EXPECT().Init(mock.Anything).Return(nil) - sender.EXPECT().Name().Return(event.CName) - sender.EXPECT().Broadcast(mock.Anything).Run(func(e *pb.Event) { - fx.events = append(fx.events, e) - }).Maybe() - fx.sender = sender - a.Register(fx.Service) - a.Register(fx.sender) - a.Register(&collectionServiceMock{updateCh: make(chan []string, 1)}) - - sbtProvider := mock_typeprovider.NewMockSmartBlockTypeProvider(t) - sbtProvider.EXPECT().Name().Return("sbtProvider") - sbtProvider.EXPECT().Init(mock.Anything).Return(nil) - - a.Register(sbtProvider) - fx.waitEvents(t, - &pb.EventMessageValueOfSubscriptionRemove{ - SubscriptionRemove: &pb.EventObjectSubscriptionRemove{ - SubId: "test", - Id: "task1", - }, - }, - &pb.EventMessageValueOfSubscriptionCounters{ - SubscriptionCounters: &pb.EventObjectSubscriptionCounters{ - SubId: "test", - Total: 0, - }, - }) - }) -} - func testCreateSubscriptionWithNestedFilter(t *testing.T) *fixtureRealStore { fx := newFixtureWithRealObjectStore(t) resp, err := fx.Search(pb.RpcObjectSearchSubscribeRequest{ diff --git a/core/subscription/sorted_test.go b/core/subscription/sorted_test.go index 6aca71c09..ef6ad3e4c 100644 --- a/core/subscription/sorted_test.go +++ b/core/subscription/sorted_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/gogo/protobuf/types" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -12,6 +11,7 @@ import ( "github.com/anyproto/anytype-heart/pkg/lib/pb/model" "github.com/anyproto/anytype-heart/util/pbtypes" "github.com/anyproto/anytype-heart/util/testMock" + "go.uber.org/mock/gomock" ) func TestSubscription_Add(t *testing.T) { diff --git a/deps/deps.go b/deps/deps.go index 1224d5f5a..acc64d461 100644 --- a/deps/deps.go +++ b/deps/deps.go @@ -1,7 +1,6 @@ package deps import ( - _ "github.com/golang/mock/sample" _ "github.com/pseudomuto/protoc-gen-doc/extensions/google_api_http" _ "github.com/vektra/mockery/v2/cmd" // _ "github.com/ahmetb/govvv" // import govvv so it can be installed with make setup-go diff --git a/go.mod b/go.mod index a6ad41956..f2dbb985b 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,6 @@ require ( github.com/gogo/status v1.1.1 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da - github.com/golang/mock v1.6.0 github.com/google/uuid v1.3.0 github.com/gosimple/slug v1.13.1 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 diff --git a/go.sum b/go.sum index 97ed65a79..fe6e556e1 100644 --- a/go.sum +++ b/go.sum @@ -1761,7 +1761,6 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= diff --git a/pkg/lib/localstore/objectstore/queries_test.go b/pkg/lib/localstore/objectstore/queries_test.go index 734a72f38..cf20c9615 100644 --- a/pkg/lib/localstore/objectstore/queries_test.go +++ b/pkg/lib/localstore/objectstore/queries_test.go @@ -519,7 +519,7 @@ func TestQueryRaw(t *testing.T) { obj3 := makeObjectWithName("id3", "name3") s.AddObjects(t, []TestObject{obj1, obj2, obj3}) - flt, err := database.NewFilters(database.Query{}, nil) + flt, err := database.NewFilters(database.Query{}, s) require.NoError(t, err) recs, err := s.QueryRaw(flt, 0, 0) @@ -572,7 +572,7 @@ func TestQueryRaw(t *testing.T) { Value: pbtypes.String("note"), }, }, - }, nil, s) + }, s) require.NoError(t, err) recs, err := s.QueryRaw(flt, 0, 0)