-
Notifications
You must be signed in to change notification settings - Fork 199
/
messengerStub.go
104 lines (86 loc) · 2.91 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
package mock
import (
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/p2p"
)
// MessengerStub -
type MessengerStub struct {
IDCalled func() core.PeerID
CloseCalled func() error
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
BootstrapCalled func() error
PeerAddressesCalled func(pid core.PeerID) []string
BroadcastOnChannelBlockingCalled func(channel string, topic string, buff []byte) error
IsConnectedToTheNetworkCalled func() bool
PeersCalled func() []core.PeerID
}
// ID -
func (ms *MessengerStub) ID() core.PeerID {
if ms.IDCalled != nil {
return ms.IDCalled()
}
return ""
}
// RegisterMessageProcessor -
func (ms *MessengerStub) RegisterMessageProcessor(topic string, handler p2p.MessageProcessor) error {
if ms.RegisterMessageProcessorCalled != nil {
return ms.RegisterMessageProcessorCalled(topic, handler)
}
return nil
}
// Broadcast -
func (ms *MessengerStub) Broadcast(topic string, buff []byte) {
ms.BroadcastCalled(topic, buff)
}
// Close -
func (ms *MessengerStub) Close() error {
return ms.CloseCalled()
}
// CreateTopic -
func (ms *MessengerStub) CreateTopic(name string, createChannelForTopic bool) error {
return ms.CreateTopicCalled(name, createChannelForTopic)
}
// HasTopic -
func (ms *MessengerStub) HasTopic(name string) bool {
return ms.HasTopicCalled(name)
}
// HasTopicValidator -
func (ms *MessengerStub) HasTopicValidator(name string) bool {
return ms.HasTopicValidatorCalled(name)
}
// BroadcastOnChannel -
func (ms *MessengerStub) BroadcastOnChannel(channel string, topic string, buff []byte) {
ms.BroadcastOnChannelCalled(channel, topic, buff)
}
// Bootstrap -
func (ms *MessengerStub) Bootstrap() error {
return ms.BootstrapCalled()
}
// PeerAddresses -
func (ms *MessengerStub) PeerAddresses(pid core.PeerID) []string {
return ms.PeerAddressesCalled(pid)
}
// BroadcastOnChannelBlocking -
func (ms *MessengerStub) BroadcastOnChannelBlocking(channel string, topic string, buff []byte) error {
return ms.BroadcastOnChannelBlockingCalled(channel, topic, buff)
}
// IsConnectedToTheNetwork -
func (ms *MessengerStub) IsConnectedToTheNetwork() bool {
return ms.IsConnectedToTheNetworkCalled()
}
// Peers -
func (ms *MessengerStub) Peers() []core.PeerID {
if ms.PeersCalled != nil {
return ms.PeersCalled()
}
return make([]core.PeerID, 0)
}
// IsInterfaceNil returns true if there is no value under the interface
func (ms *MessengerStub) IsInterfaceNil() bool {
return ms == nil
}