Add push space custom matchers
This commit is contained in:
parent
68ed132e61
commit
c01441460b
@ -9,12 +9,44 @@ import (
|
|||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto"
|
||||||
|
storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ldiff"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ldiff"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"storj.io/drpc"
|
"storj.io/drpc"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type pushSpaceRequestMatcher struct {
|
||||||
|
spaceId string
|
||||||
|
aclRoot *aclrecordproto.RawACLRecordWithId
|
||||||
|
spaceHeader *spacesyncproto.SpaceHeader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p pushSpaceRequestMatcher) Matches(x interface{}) bool {
|
||||||
|
res, ok := x.(*spacesyncproto.PushSpaceRequest)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.SpaceId == p.spaceId && res.AclRoot == p.aclRoot && res.SpaceHeader == p.spaceHeader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p pushSpaceRequestMatcher) String() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPushSpaceRequestMatcher(
|
||||||
|
spaceId string,
|
||||||
|
aclRoot *aclrecordproto.RawACLRecordWithId,
|
||||||
|
spaceHeader *spacesyncproto.SpaceHeader) *pushSpaceRequestMatcher {
|
||||||
|
return &pushSpaceRequestMatcher{
|
||||||
|
spaceId: spaceId,
|
||||||
|
aclRoot: aclRoot,
|
||||||
|
spaceHeader: spaceHeader,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDiffSyncer_Sync(t *testing.T) {
|
func TestDiffSyncer_Sync(t *testing.T) {
|
||||||
// setup
|
// setup
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -40,12 +72,38 @@ func TestDiffSyncer_Sync(t *testing.T) {
|
|||||||
diffMock.EXPECT().
|
diffMock.EXPECT().
|
||||||
Diff(gomock.Any(), gomock.Eq(remotediff.NewRemoteDiff(spaceId, clientMock))).
|
Diff(gomock.Any(), gomock.Eq(remotediff.NewRemoteDiff(spaceId, clientMock))).
|
||||||
Return([]string{"new"}, []string{"changed"}, nil, nil)
|
Return([]string{"new"}, []string{"changed"}, nil, nil)
|
||||||
|
for _, arg := range []string{"new", "changed"} {
|
||||||
cacheMock.EXPECT().
|
cacheMock.EXPECT().
|
||||||
GetTree(gomock.Any(), spaceId, "new").
|
GetTree(gomock.Any(), spaceId, arg).
|
||||||
Return(cache.TreeResult{}, nil)
|
|
||||||
cacheMock.EXPECT().
|
|
||||||
GetTree(gomock.Any(), spaceId, "changed").
|
|
||||||
Return(cache.TreeResult{}, nil)
|
Return(cache.TreeResult{}, nil)
|
||||||
|
}
|
||||||
|
_ = diffSyncer.Sync(ctx)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("diff syncer sync space missing", func(t *testing.T) {
|
||||||
|
aclStorageMock := storage2.NewMockListStorage(ctrl)
|
||||||
|
aclRoot := &aclrecordproto.RawACLRecordWithId{}
|
||||||
|
spaceHeader := &spacesyncproto.SpaceHeader{}
|
||||||
|
|
||||||
|
nconfMock.EXPECT().
|
||||||
|
ResponsiblePeers(gomock.Any(), spaceId).
|
||||||
|
Return([]peer.Peer{nil}, nil)
|
||||||
|
diffMock.EXPECT().
|
||||||
|
Diff(gomock.Any(), gomock.Eq(remotediff.NewRemoteDiff(spaceId, clientMock))).
|
||||||
|
Return(nil, nil, nil, spacesyncproto.ErrSpaceMissing)
|
||||||
|
stMock.EXPECT().
|
||||||
|
ACLStorage().
|
||||||
|
Return(aclStorageMock, nil)
|
||||||
|
stMock.EXPECT().
|
||||||
|
SpaceHeader().
|
||||||
|
Return(spaceHeader, nil)
|
||||||
|
aclStorageMock.EXPECT().
|
||||||
|
Root().
|
||||||
|
Return(aclRoot, nil)
|
||||||
|
clientMock.EXPECT().
|
||||||
|
PushSpace(gomock.Any(), newPushSpaceRequestMatcher(spaceId, aclRoot, spaceHeader)).
|
||||||
|
Return(nil, nil)
|
||||||
|
|
||||||
_ = diffSyncer.Sync(ctx)
|
_ = diffSyncer.Sync(ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
//go:generate mockgen -package storage -destination liststorage_mock.go github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage ListStorage
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
110
pkg/acl/storage/liststorage_mock.go
Normal file
110
pkg/acl/storage/liststorage_mock.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
|
// Source: github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage (interfaces: ListStorage)
|
||||||
|
|
||||||
|
// Package storage is a generated GoMock package.
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
reflect "reflect"
|
||||||
|
|
||||||
|
aclrecordproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto"
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockListStorage is a mock of ListStorage interface.
|
||||||
|
type MockListStorage struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockListStorageMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockListStorageMockRecorder is the mock recorder for MockListStorage.
|
||||||
|
type MockListStorageMockRecorder struct {
|
||||||
|
mock *MockListStorage
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockListStorage creates a new mock instance.
|
||||||
|
func NewMockListStorage(ctrl *gomock.Controller) *MockListStorage {
|
||||||
|
mock := &MockListStorage{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockListStorageMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockListStorage) EXPECT() *MockListStorageMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddRawRecord mocks base method.
|
||||||
|
func (m *MockListStorage) AddRawRecord(arg0 context.Context, arg1 *aclrecordproto.RawACLRecordWithId) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "AddRawRecord", arg0, arg1)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddRawRecord indicates an expected call of AddRawRecord.
|
||||||
|
func (mr *MockListStorageMockRecorder) AddRawRecord(arg0, arg1 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRawRecord", reflect.TypeOf((*MockListStorage)(nil).AddRawRecord), arg0, arg1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRawRecord mocks base method.
|
||||||
|
func (m *MockListStorage) GetRawRecord(arg0 context.Context, arg1 string) (*aclrecordproto.RawACLRecordWithId, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "GetRawRecord", arg0, arg1)
|
||||||
|
ret0, _ := ret[0].(*aclrecordproto.RawACLRecordWithId)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRawRecord indicates an expected call of GetRawRecord.
|
||||||
|
func (mr *MockListStorageMockRecorder) GetRawRecord(arg0, arg1 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRawRecord", reflect.TypeOf((*MockListStorage)(nil).GetRawRecord), arg0, arg1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Head mocks base method.
|
||||||
|
func (m *MockListStorage) Head() (*aclrecordproto.RawACLRecordWithId, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Head")
|
||||||
|
ret0, _ := ret[0].(*aclrecordproto.RawACLRecordWithId)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Head indicates an expected call of Head.
|
||||||
|
func (mr *MockListStorageMockRecorder) Head() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Head", reflect.TypeOf((*MockListStorage)(nil).Head))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID mocks base method.
|
||||||
|
func (m *MockListStorage) ID() (string, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "ID")
|
||||||
|
ret0, _ := ret[0].(string)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID indicates an expected call of ID.
|
||||||
|
func (mr *MockListStorageMockRecorder) ID() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ID", reflect.TypeOf((*MockListStorage)(nil).ID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Root mocks base method.
|
||||||
|
func (m *MockListStorage) Root() (*aclrecordproto.RawACLRecordWithId, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Root")
|
||||||
|
ret0, _ := ret[0].(*aclrecordproto.RawACLRecordWithId)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Root indicates an expected call of Root.
|
||||||
|
func (mr *MockListStorageMockRecorder) Root() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Root", reflect.TypeOf((*MockListStorage)(nil).Root))
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user