From f05eca3f8ae9f749783c2153b3c50d0b01383cba Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 13 Feb 2019 09:45:50 -0800 Subject: [PATCH] Unexport internally used interfaces --- p2p/host/hostv2/hostv2.go | 12 ++--- p2p/host/hostv2/hostv2_test.go | 12 ++--- p2p/host/hostv2/mock/hostv2_mock.go | 68 ++++++++++++++--------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/p2p/host/hostv2/hostv2.go b/p2p/host/hostv2/hostv2.go index 381dd7099..906c4fd10 100644 --- a/p2p/host/hostv2/hostv2.go +++ b/p2p/host/hostv2/hostv2.go @@ -32,8 +32,8 @@ const ( numOutgoing = 16 ) -// PubSub captures the pubsub interface we expect from libp2p. -type PubSub interface { +// pubsub captures the pubsub interface we expect from libp2p. +type pubsub interface { Publish(topic string, data []byte) error Subscribe(topic string, opts ...libp2p_pubsub.SubOpt) (*libp2p_pubsub.Subscription, error) } @@ -41,7 +41,7 @@ type PubSub interface { // HostV2 is the version 2 p2p host type HostV2 struct { h p2p_host.Host - pubsub PubSub + pubsub pubsub self p2p.Peer priKey p2p_crypto.PrivKey lock sync.Mutex @@ -62,15 +62,15 @@ func (host *HostV2) SendMessageToGroups(groups []p2p.GroupID, msg []byte) error return error } -// Subscription captures the subscription interface -type Subscription interface { +// subscription captures the subscription interface we expect from libp2p. +type subscription interface { Next(ctx context.Context) (*libp2p_pubsub.Message, error) Cancel() } // GroupReceiverImpl is a multicast group receiver implementation. type GroupReceiverImpl struct { - sub Subscription + sub subscription } // Close closes this receiver. diff --git a/p2p/host/hostv2/hostv2_test.go b/p2p/host/hostv2/hostv2_test.go index 6cfc38dd5..176874b43 100644 --- a/p2p/host/hostv2/hostv2_test.go +++ b/p2p/host/hostv2/hostv2_test.go @@ -22,7 +22,7 @@ func TestHostV2_SendMessageToGroups(t *testing.T) { defer mc.Finish() groups := []p2p.GroupID{"ABC", "DEF"} data := []byte{1, 2, 3} - pubsub := mock.NewMockPubSub(mc) + pubsub := mock.NewMockpubsub(mc) gomock.InOrder( pubsub.EXPECT().Publish("ABC", data), pubsub.EXPECT().Publish("DEF", data), @@ -37,7 +37,7 @@ func TestHostV2_SendMessageToGroups(t *testing.T) { defer mc.Finish() groups := []p2p.GroupID{"ABC", "DEF"} data := []byte{1, 2, 3} - pubsub := mock.NewMockPubSub(mc) + pubsub := mock.NewMockpubsub(mc) gomock.InOrder( pubsub.EXPECT().Publish("ABC", data).Return(errors.New("FIAL")), pubsub.EXPECT().Publish("DEF", data), // Should not early-return @@ -52,7 +52,7 @@ func TestHostV2_SendMessageToGroups(t *testing.T) { func TestGroupReceiver_Close(t *testing.T) { mc := gomock.NewController(t) defer mc.Finish() - sub := mock.NewMockSubscription(mc) + sub := mock.NewMocksubscription(mc) sub.EXPECT().Cancel() receiver := GroupReceiverImpl{sub: sub} if err := receiver.Close(); err != nil { @@ -68,7 +68,7 @@ func pubsubMessage(from peer.ID, data []byte) *libp2p_pubsub.Message { func TestGroupReceiver_Receive(t *testing.T) { mc := gomock.NewController(t) defer mc.Finish() - sub := mock.NewMockSubscription(mc) + sub := mock.NewMocksubscription(mc) ctx, _ := context.WithCancel(context.Background()) gomock.InOrder( sub.EXPECT().Next(ctx).Return(pubsubMessage("ABC", []byte{1, 2, 3}), nil), @@ -102,7 +102,7 @@ func TestHostV2_GroupReceiver(t *testing.T) { mc := gomock.NewController(t) defer mc.Finish() sub := &libp2p_pubsub.Subscription{} - pubsub := mock.NewMockPubSub(mc) + pubsub := mock.NewMockpubsub(mc) pubsub.EXPECT().Subscribe("ABC").Return(sub, nil) host := &HostV2{pubsub: pubsub} gotReceiver, err := host.GroupReceiver("ABC") @@ -118,7 +118,7 @@ func TestHostV2_GroupReceiver(t *testing.T) { t.Run("Error", func(t *testing.T) { mc := gomock.NewController(t) defer mc.Finish() - pubsub := mock.NewMockPubSub(mc) + pubsub := mock.NewMockpubsub(mc) pubsub.EXPECT().Subscribe("ABC").Return(nil, errors.New("FIAL")) host := &HostV2{pubsub: pubsub} gotReceiver, err := host.GroupReceiver("ABC") diff --git a/p2p/host/hostv2/mock/hostv2_mock.go b/p2p/host/hostv2/mock/hostv2_mock.go index 29fe18918..d86af79c9 100644 --- a/p2p/host/hostv2/mock/hostv2_mock.go +++ b/p2p/host/hostv2/mock/hostv2_mock.go @@ -11,43 +11,43 @@ import ( reflect "reflect" ) -// MockPubSub is a mock of PubSub interface -type MockPubSub struct { +// Mockpubsub is a mock of pubsub interface +type Mockpubsub struct { ctrl *gomock.Controller - recorder *MockPubSubMockRecorder + recorder *MockpubsubMockRecorder } -// MockPubSubMockRecorder is the mock recorder for MockPubSub -type MockPubSubMockRecorder struct { - mock *MockPubSub +// MockpubsubMockRecorder is the mock recorder for Mockpubsub +type MockpubsubMockRecorder struct { + mock *Mockpubsub } -// NewMockPubSub creates a new mock instance -func NewMockPubSub(ctrl *gomock.Controller) *MockPubSub { - mock := &MockPubSub{ctrl: ctrl} - mock.recorder = &MockPubSubMockRecorder{mock} +// NewMockpubsub creates a new mock instance +func NewMockpubsub(ctrl *gomock.Controller) *Mockpubsub { + mock := &Mockpubsub{ctrl: ctrl} + mock.recorder = &MockpubsubMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use -func (m *MockPubSub) EXPECT() *MockPubSubMockRecorder { +func (m *Mockpubsub) EXPECT() *MockpubsubMockRecorder { return m.recorder } // Publish mocks base method -func (m *MockPubSub) Publish(topic string, data []byte) error { +func (m *Mockpubsub) Publish(topic string, data []byte) error { ret := m.ctrl.Call(m, "Publish", topic, data) ret0, _ := ret[0].(error) return ret0 } // Publish indicates an expected call of Publish -func (mr *MockPubSubMockRecorder) Publish(topic, data interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Publish", reflect.TypeOf((*MockPubSub)(nil).Publish), topic, data) +func (mr *MockpubsubMockRecorder) Publish(topic, data interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Publish", reflect.TypeOf((*Mockpubsub)(nil).Publish), topic, data) } // Subscribe mocks base method -func (m *MockPubSub) Subscribe(topic string, opts ...go_libp2p_pubsub.SubOpt) (*go_libp2p_pubsub.Subscription, error) { +func (m *Mockpubsub) Subscribe(topic string, opts ...go_libp2p_pubsub.SubOpt) (*go_libp2p_pubsub.Subscription, error) { varargs := []interface{}{topic} for _, a := range opts { varargs = append(varargs, a) @@ -59,36 +59,36 @@ func (m *MockPubSub) Subscribe(topic string, opts ...go_libp2p_pubsub.SubOpt) (* } // Subscribe indicates an expected call of Subscribe -func (mr *MockPubSubMockRecorder) Subscribe(topic interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockpubsubMockRecorder) Subscribe(topic interface{}, opts ...interface{}) *gomock.Call { varargs := append([]interface{}{topic}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Subscribe", reflect.TypeOf((*MockPubSub)(nil).Subscribe), varargs...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Subscribe", reflect.TypeOf((*Mockpubsub)(nil).Subscribe), varargs...) } -// MockSubscription is a mock of Subscription interface -type MockSubscription struct { +// Mocksubscription is a mock of subscription interface +type Mocksubscription struct { ctrl *gomock.Controller - recorder *MockSubscriptionMockRecorder + recorder *MocksubscriptionMockRecorder } -// MockSubscriptionMockRecorder is the mock recorder for MockSubscription -type MockSubscriptionMockRecorder struct { - mock *MockSubscription +// MocksubscriptionMockRecorder is the mock recorder for Mocksubscription +type MocksubscriptionMockRecorder struct { + mock *Mocksubscription } -// NewMockSubscription creates a new mock instance -func NewMockSubscription(ctrl *gomock.Controller) *MockSubscription { - mock := &MockSubscription{ctrl: ctrl} - mock.recorder = &MockSubscriptionMockRecorder{mock} +// NewMocksubscription creates a new mock instance +func NewMocksubscription(ctrl *gomock.Controller) *Mocksubscription { + mock := &Mocksubscription{ctrl: ctrl} + mock.recorder = &MocksubscriptionMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use -func (m *MockSubscription) EXPECT() *MockSubscriptionMockRecorder { +func (m *Mocksubscription) EXPECT() *MocksubscriptionMockRecorder { return m.recorder } // Next mocks base method -func (m *MockSubscription) Next(ctx context.Context) (*go_libp2p_pubsub.Message, error) { +func (m *Mocksubscription) Next(ctx context.Context) (*go_libp2p_pubsub.Message, error) { ret := m.ctrl.Call(m, "Next", ctx) ret0, _ := ret[0].(*go_libp2p_pubsub.Message) ret1, _ := ret[1].(error) @@ -96,16 +96,16 @@ func (m *MockSubscription) Next(ctx context.Context) (*go_libp2p_pubsub.Message, } // Next indicates an expected call of Next -func (mr *MockSubscriptionMockRecorder) Next(ctx interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Next", reflect.TypeOf((*MockSubscription)(nil).Next), ctx) +func (mr *MocksubscriptionMockRecorder) Next(ctx interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Next", reflect.TypeOf((*Mocksubscription)(nil).Next), ctx) } // Cancel mocks base method -func (m *MockSubscription) Cancel() { +func (m *Mocksubscription) Cancel() { m.ctrl.Call(m, "Cancel") } // Cancel indicates an expected call of Cancel -func (mr *MockSubscriptionMockRecorder) Cancel() *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cancel", reflect.TypeOf((*MockSubscription)(nil).Cancel)) +func (mr *MocksubscriptionMockRecorder) Cancel() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cancel", reflect.TypeOf((*Mocksubscription)(nil).Cancel)) }