-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventBusStub.go
41 lines (32 loc) · 1.04 KB
/
eventBusStub.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
package mock
import (
"reflect"
"github.com/libp2p/go-libp2p/core/event"
)
// EventBusStub -
type EventBusStub struct {
SubscribeCalled func(eventType interface{}, opts ...event.SubscriptionOpt) (event.Subscription, error)
EmitterCalled func(eventType interface{}, opts ...event.EmitterOpt) (event.Emitter, error)
GetAllEventTypesCalled func() []reflect.Type
}
// Subscribe -
func (ebs *EventBusStub) Subscribe(eventType interface{}, opts ...event.SubscriptionOpt) (event.Subscription, error) {
if ebs.SubscribeCalled != nil {
return ebs.SubscribeCalled(eventType, opts...)
}
return &EventSubscriptionStub{}, nil
}
// Emitter -
func (ebs *EventBusStub) Emitter(eventType interface{}, opts ...event.EmitterOpt) (event.Emitter, error) {
if ebs.EmitterCalled != nil {
return ebs.EmitterCalled(eventType, opts...)
}
return nil, nil
}
// GetAllEventTypes -
func (ebs *EventBusStub) GetAllEventTypes() []reflect.Type {
if ebs.GetAllEventTypesCalled != nil {
return ebs.GetAllEventTypesCalled()
}
return make([]reflect.Type, 0)
}