fix handshake test
This commit is contained in:
parent
aab53579e0
commit
55878490e9
@ -6,7 +6,9 @@ import (
|
||||
"github.com/anytypeio/any-sync/app"
|
||||
"github.com/anytypeio/any-sync/net/peer"
|
||||
"github.com/anytypeio/any-sync/nodeconf"
|
||||
"github.com/anytypeio/any-sync/nodeconf/mock_nodeconf"
|
||||
"github.com/anytypeio/any-sync/testutil/testnodeconf"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"net"
|
||||
@ -19,7 +21,6 @@ func TestHandshake(t *testing.T) {
|
||||
nc := testnodeconf.GenNodeConfig(2)
|
||||
fxS := newFixture(t, nc, nc.GetAccountService(0))
|
||||
defer fxS.Finish(t)
|
||||
|
||||
sc, cc := net.Pipe()
|
||||
|
||||
type acceptRes struct {
|
||||
@ -53,20 +54,28 @@ func TestHandshake(t *testing.T) {
|
||||
|
||||
func newFixture(t *testing.T, nc *testnodeconf.Config, acc accountservice.Service) *fixture {
|
||||
fx := &fixture{
|
||||
ctrl: gomock.NewController(t),
|
||||
secureService: New().(*secureService),
|
||||
acc: acc,
|
||||
a: new(app.App),
|
||||
}
|
||||
|
||||
fx.a.Register(fx.acc).Register(nc).Register(nodeconf.New()).Register(fx.secureService)
|
||||
fx.mockNodeConf = mock_nodeconf.NewMockService(fx.ctrl)
|
||||
fx.mockNodeConf.EXPECT().Init(gomock.Any())
|
||||
fx.mockNodeConf.EXPECT().Name().Return(nodeconf.CName).AnyTimes()
|
||||
fx.mockNodeConf.EXPECT().Run(ctx)
|
||||
fx.mockNodeConf.EXPECT().Close(ctx)
|
||||
fx.mockNodeConf.EXPECT().NodeTypes(gomock.Any()).Return([]nodeconf.NodeType{nodeconf.NodeTypeTree}).AnyTimes()
|
||||
fx.a.Register(fx.acc).Register(nc).Register(fx.mockNodeConf).Register(fx.secureService)
|
||||
require.NoError(t, fx.a.Start(ctx))
|
||||
return fx
|
||||
}
|
||||
|
||||
type fixture struct {
|
||||
*secureService
|
||||
a *app.App
|
||||
acc accountservice.Service
|
||||
a *app.App
|
||||
acc accountservice.Service
|
||||
ctrl *gomock.Controller
|
||||
mockNodeConf *mock_nodeconf.MockService
|
||||
}
|
||||
|
||||
func (fx *fixture) Finish(t *testing.T) {
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/anytypeio/any-sync/nodeconf (interfaces: Service,Configuration)
|
||||
// Source: github.com/anytypeio/any-sync/nodeconf (interfaces: Service)
|
||||
|
||||
// Package mock_nodeconf is a generated GoMock package.
|
||||
package mock_nodeconf
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
app "github.com/anytypeio/any-sync/app"
|
||||
@ -36,32 +37,102 @@ func (m *MockService) EXPECT() *MockServiceMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetById mocks base method.
|
||||
func (m *MockService) GetById(arg0 string) nodeconf.Configuration {
|
||||
// CHash mocks base method.
|
||||
func (m *MockService) CHash() chash.CHash {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetById", arg0)
|
||||
ret := m.ctrl.Call(m, "CHash")
|
||||
ret0, _ := ret[0].(chash.CHash)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// CHash indicates an expected call of CHash.
|
||||
func (mr *MockServiceMockRecorder) CHash() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CHash", reflect.TypeOf((*MockService)(nil).CHash))
|
||||
}
|
||||
|
||||
// Close mocks base method.
|
||||
func (m *MockService) Close(arg0 context.Context) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Close", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Close indicates an expected call of Close.
|
||||
func (mr *MockServiceMockRecorder) Close(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockService)(nil).Close), arg0)
|
||||
}
|
||||
|
||||
// Configuration mocks base method.
|
||||
func (m *MockService) Configuration() nodeconf.Configuration {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Configuration")
|
||||
ret0, _ := ret[0].(nodeconf.Configuration)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetById indicates an expected call of GetById.
|
||||
func (mr *MockServiceMockRecorder) GetById(arg0 interface{}) *gomock.Call {
|
||||
// Configuration indicates an expected call of Configuration.
|
||||
func (mr *MockServiceMockRecorder) Configuration() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetById", reflect.TypeOf((*MockService)(nil).GetById), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Configuration", reflect.TypeOf((*MockService)(nil).Configuration))
|
||||
}
|
||||
|
||||
// GetLast mocks base method.
|
||||
func (m *MockService) GetLast() nodeconf.Configuration {
|
||||
// ConsensusPeers mocks base method.
|
||||
func (m *MockService) ConsensusPeers() []string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetLast")
|
||||
ret0, _ := ret[0].(nodeconf.Configuration)
|
||||
ret := m.ctrl.Call(m, "ConsensusPeers")
|
||||
ret0, _ := ret[0].([]string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetLast indicates an expected call of GetLast.
|
||||
func (mr *MockServiceMockRecorder) GetLast() *gomock.Call {
|
||||
// ConsensusPeers indicates an expected call of ConsensusPeers.
|
||||
func (mr *MockServiceMockRecorder) ConsensusPeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLast", reflect.TypeOf((*MockService)(nil).GetLast))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusPeers", reflect.TypeOf((*MockService)(nil).ConsensusPeers))
|
||||
}
|
||||
|
||||
// CoordinatorPeers mocks base method.
|
||||
func (m *MockService) CoordinatorPeers() []string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CoordinatorPeers")
|
||||
ret0, _ := ret[0].([]string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// CoordinatorPeers indicates an expected call of CoordinatorPeers.
|
||||
func (mr *MockServiceMockRecorder) CoordinatorPeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CoordinatorPeers", reflect.TypeOf((*MockService)(nil).CoordinatorPeers))
|
||||
}
|
||||
|
||||
// FilePeers mocks base method.
|
||||
func (m *MockService) FilePeers() []string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "FilePeers")
|
||||
ret0, _ := ret[0].([]string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// FilePeers indicates an expected call of FilePeers.
|
||||
func (mr *MockServiceMockRecorder) FilePeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilePeers", reflect.TypeOf((*MockService)(nil).FilePeers))
|
||||
}
|
||||
|
||||
// Id mocks base method.
|
||||
func (m *MockService) Id() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Id")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Id indicates an expected call of Id.
|
||||
func (mr *MockServiceMockRecorder) Id() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Id", reflect.TypeOf((*MockService)(nil).Id))
|
||||
}
|
||||
|
||||
// Init mocks base method.
|
||||
@ -78,6 +149,20 @@ func (mr *MockServiceMockRecorder) Init(arg0 interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockService)(nil).Init), arg0)
|
||||
}
|
||||
|
||||
// IsResponsible mocks base method.
|
||||
func (m *MockService) IsResponsible(arg0 string) bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "IsResponsible", arg0)
|
||||
ret0, _ := ret[0].(bool)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// IsResponsible indicates an expected call of IsResponsible.
|
||||
func (mr *MockServiceMockRecorder) IsResponsible(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsResponsible", reflect.TypeOf((*MockService)(nil).IsResponsible), arg0)
|
||||
}
|
||||
|
||||
// Name mocks base method.
|
||||
func (m *MockService) Name() string {
|
||||
m.ctrl.T.Helper()
|
||||
@ -92,129 +177,8 @@ func (mr *MockServiceMockRecorder) Name() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockService)(nil).Name))
|
||||
}
|
||||
|
||||
// MockConfiguration is a mock of Configuration interface.
|
||||
type MockConfiguration struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockConfigurationMockRecorder
|
||||
}
|
||||
|
||||
// MockConfigurationMockRecorder is the mock recorder for MockConfiguration.
|
||||
type MockConfigurationMockRecorder struct {
|
||||
mock *MockConfiguration
|
||||
}
|
||||
|
||||
// NewMockConfiguration creates a new mock instance.
|
||||
func NewMockConfiguration(ctrl *gomock.Controller) *MockConfiguration {
|
||||
mock := &MockConfiguration{ctrl: ctrl}
|
||||
mock.recorder = &MockConfigurationMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockConfiguration) EXPECT() *MockConfigurationMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Addresses mocks base method.
|
||||
func (m *MockConfiguration) Addresses() map[string][]string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Addresses")
|
||||
ret0, _ := ret[0].(map[string][]string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Addresses indicates an expected call of Addresses.
|
||||
func (mr *MockConfigurationMockRecorder) Addresses() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Addresses", reflect.TypeOf((*MockConfiguration)(nil).Addresses))
|
||||
}
|
||||
|
||||
// CHash mocks base method.
|
||||
func (m *MockConfiguration) CHash() chash.CHash {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CHash")
|
||||
ret0, _ := ret[0].(chash.CHash)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// CHash indicates an expected call of CHash.
|
||||
func (mr *MockConfigurationMockRecorder) CHash() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CHash", reflect.TypeOf((*MockConfiguration)(nil).CHash))
|
||||
}
|
||||
|
||||
// ConsensusPeers mocks base method.
|
||||
func (m *MockConfiguration) ConsensusPeers() []string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ConsensusPeers")
|
||||
ret0, _ := ret[0].([]string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ConsensusPeers indicates an expected call of ConsensusPeers.
|
||||
func (mr *MockConfigurationMockRecorder) ConsensusPeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusPeers", reflect.TypeOf((*MockConfiguration)(nil).ConsensusPeers))
|
||||
}
|
||||
|
||||
// CoordinatorPeers mocks base method.
|
||||
func (m *MockConfiguration) CoordinatorPeers() []string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CoordinatorPeers")
|
||||
ret0, _ := ret[0].([]string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// CoordinatorPeers indicates an expected call of CoordinatorPeers.
|
||||
func (mr *MockConfigurationMockRecorder) CoordinatorPeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CoordinatorPeers", reflect.TypeOf((*MockConfiguration)(nil).CoordinatorPeers))
|
||||
}
|
||||
|
||||
// FilePeers mocks base method.
|
||||
func (m *MockConfiguration) FilePeers() []string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "FilePeers")
|
||||
ret0, _ := ret[0].([]string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// FilePeers indicates an expected call of FilePeers.
|
||||
func (mr *MockConfigurationMockRecorder) FilePeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilePeers", reflect.TypeOf((*MockConfiguration)(nil).FilePeers))
|
||||
}
|
||||
|
||||
// Id mocks base method.
|
||||
func (m *MockConfiguration) Id() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Id")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Id indicates an expected call of Id.
|
||||
func (mr *MockConfigurationMockRecorder) Id() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Id", reflect.TypeOf((*MockConfiguration)(nil).Id))
|
||||
}
|
||||
|
||||
// IsResponsible mocks base method.
|
||||
func (m *MockConfiguration) IsResponsible(arg0 string) bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "IsResponsible", arg0)
|
||||
ret0, _ := ret[0].(bool)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// IsResponsible indicates an expected call of IsResponsible.
|
||||
func (mr *MockConfigurationMockRecorder) IsResponsible(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsResponsible", reflect.TypeOf((*MockConfiguration)(nil).IsResponsible), arg0)
|
||||
}
|
||||
|
||||
// NodeIds mocks base method.
|
||||
func (m *MockConfiguration) NodeIds(arg0 string) []string {
|
||||
func (m *MockService) NodeIds(arg0 string) []string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "NodeIds", arg0)
|
||||
ret0, _ := ret[0].([]string)
|
||||
@ -222,13 +186,13 @@ func (m *MockConfiguration) NodeIds(arg0 string) []string {
|
||||
}
|
||||
|
||||
// NodeIds indicates an expected call of NodeIds.
|
||||
func (mr *MockConfigurationMockRecorder) NodeIds(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockServiceMockRecorder) NodeIds(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeIds", reflect.TypeOf((*MockConfiguration)(nil).NodeIds), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeIds", reflect.TypeOf((*MockService)(nil).NodeIds), arg0)
|
||||
}
|
||||
|
||||
// NodeTypes mocks base method.
|
||||
func (m *MockConfiguration) NodeTypes(arg0 string) []nodeconf.NodeType {
|
||||
func (m *MockService) NodeTypes(arg0 string) []nodeconf.NodeType {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "NodeTypes", arg0)
|
||||
ret0, _ := ret[0].([]nodeconf.NodeType)
|
||||
@ -236,13 +200,13 @@ func (m *MockConfiguration) NodeTypes(arg0 string) []nodeconf.NodeType {
|
||||
}
|
||||
|
||||
// NodeTypes indicates an expected call of NodeTypes.
|
||||
func (mr *MockConfigurationMockRecorder) NodeTypes(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockServiceMockRecorder) NodeTypes(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeTypes", reflect.TypeOf((*MockConfiguration)(nil).NodeTypes), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeTypes", reflect.TypeOf((*MockService)(nil).NodeTypes), arg0)
|
||||
}
|
||||
|
||||
// Partition mocks base method.
|
||||
func (m *MockConfiguration) Partition(arg0 string) int {
|
||||
func (m *MockService) Partition(arg0 string) int {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Partition", arg0)
|
||||
ret0, _ := ret[0].(int)
|
||||
@ -250,7 +214,36 @@ func (m *MockConfiguration) Partition(arg0 string) int {
|
||||
}
|
||||
|
||||
// Partition indicates an expected call of Partition.
|
||||
func (mr *MockConfigurationMockRecorder) Partition(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockServiceMockRecorder) Partition(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Partition", reflect.TypeOf((*MockConfiguration)(nil).Partition), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Partition", reflect.TypeOf((*MockService)(nil).Partition), arg0)
|
||||
}
|
||||
|
||||
// PeerAddresses mocks base method.
|
||||
func (m *MockService) PeerAddresses(arg0 string) ([]string, bool) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PeerAddresses", arg0)
|
||||
ret0, _ := ret[0].([]string)
|
||||
ret1, _ := ret[1].(bool)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// PeerAddresses indicates an expected call of PeerAddresses.
|
||||
func (mr *MockServiceMockRecorder) PeerAddresses(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerAddresses", reflect.TypeOf((*MockService)(nil).PeerAddresses), arg0)
|
||||
}
|
||||
|
||||
// Run mocks base method.
|
||||
func (m *MockService) Run(arg0 context.Context) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Run", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Run indicates an expected call of Run.
|
||||
func (mr *MockServiceMockRecorder) Run(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockService)(nil).Run), arg0)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user