mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-07 21:37:04 +09:00
GO-1777: Fix tests
This commit is contained in:
parent
7c501b61cd
commit
8c5dc07b81
8 changed files with 36 additions and 75 deletions
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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) {
|
||||
|
|
1
deps/deps.go
vendored
1
deps/deps.go
vendored
|
@ -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
|
||||
|
|
1
go.mod
1
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
|
||||
|
|
1
go.sum
1
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=
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue