-
Notifications
You must be signed in to change notification settings - Fork 199
/
messengerStub.go
106 lines (85 loc) · 3.25 KB
/
messengerStub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package mock
import (
"github.com/ElrondNetwork/elrond-go/p2p"
)
type MessengerStub struct {
CloseCalled func() error
IDCalled func() p2p.PeerID
PeersCalled func() []p2p.PeerID
AddressesCalled func() []string
ConnectToPeerCalled func(address string) error
TrimConnectionsCalled func()
IsConnectedCalled func(peerID p2p.PeerID) bool
ConnectedPeersCalled func() []p2p.PeerID
CreateTopicCalled func(name string, createChannelForTopic bool) error
HasTopicCalled func(name string) bool
HasTopicValidatorCalled func(name string) bool
BroadcastOnChannelCalled func(channel string, topic string, buff []byte)
BroadcastCalled func(topic string, buff []byte)
RegisterMessageProcessorCalled func(topic string, handler p2p.MessageProcessor) error
UnregisterMessageProcessorCalled func(topic string) error
SendToConnectedPeerCalled func(topic string, buff []byte, peerID p2p.PeerID) error
OutgoingChannelLoadBalancerCalled func() p2p.ChannelLoadBalancer
BootstrapCalled func() error
}
func (ms *MessengerStub) RegisterMessageProcessor(topic string, handler p2p.MessageProcessor) error {
return ms.RegisterMessageProcessorCalled(topic, handler)
}
func (ms *MessengerStub) UnregisterMessageProcessor(topic string) error {
return ms.UnregisterMessageProcessorCalled(topic)
}
func (ms *MessengerStub) Broadcast(topic string, buff []byte) {
ms.BroadcastCalled(topic, buff)
}
func (ms *MessengerStub) OutgoingChannelLoadBalancer() p2p.ChannelLoadBalancer {
return ms.OutgoingChannelLoadBalancerCalled()
}
func (ms *MessengerStub) Close() error {
return ms.CloseCalled()
}
func (ms *MessengerStub) ID() p2p.PeerID {
return ms.IDCalled()
}
func (ms *MessengerStub) Peers() []p2p.PeerID {
return ms.PeersCalled()
}
func (ms *MessengerStub) Addresses() []string {
return ms.AddressesCalled()
}
func (ms *MessengerStub) ConnectToPeer(address string) error {
return ms.ConnectToPeerCalled(address)
}
func (ms *MessengerStub) TrimConnections() {
ms.TrimConnectionsCalled()
}
func (ms *MessengerStub) IsConnected(peerID p2p.PeerID) bool {
return ms.IsConnectedCalled(peerID)
}
func (ms *MessengerStub) ConnectedPeers() []p2p.PeerID {
return ms.ConnectedPeersCalled()
}
func (ms *MessengerStub) CreateTopic(name string, createChannelForTopic bool) error {
return ms.CreateTopicCalled(name, createChannelForTopic)
}
func (ms *MessengerStub) HasTopic(name string) bool {
return ms.HasTopicCalled(name)
}
func (ms *MessengerStub) HasTopicValidator(name string) bool {
return ms.HasTopicValidatorCalled(name)
}
func (ms *MessengerStub) BroadcastOnChannel(channel string, topic string, buff []byte) {
ms.BroadcastOnChannelCalled(channel, topic, buff)
}
func (ms *MessengerStub) SendToConnectedPeer(topic string, buff []byte, peerID p2p.PeerID) error {
return ms.SendToConnectedPeerCalled(topic, buff, peerID)
}
func (ms *MessengerStub) Bootstrap() error {
return ms.BootstrapCalled()
}
// IsInterfaceNil returns true if there is no value under the interface
func (ms *MessengerStub) IsInterfaceNil() bool {
if ms == nil {
return true
}
return false
}