-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_source_mock.go
81 lines (75 loc) · 2.45 KB
/
event_source_mock.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
package glocbus
import (
"context"
"github.com/cloudevents/sdk-go/v2/event"
"github.com/stretchr/testify/mock"
)
// Mock for an event source.
type EventSourceMock struct {
mock.Mock
}
// # Description
//
// Provide the channel used by the event source to publish its events.
//
// # Implementation requirements & hints
//
// - The method must return the same channel instance to all callers.
// - The source must provide its publication channel even if it has not been started yet.
// - The source must continue providing the same channel even if the source has been stopped.
// - To achieve end to end event traceability, events are expected to embed tracing data as
// described in the following documentation:
// https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/extensions/distributed-tracing.md
//
// # Return
//
// The channel used by this source to publish its events.
func (mock *EventSourceMock) GetChannel() chan event.Event {
args := mock.Called()
return args.Get(0).(chan event.Event)
}
// # Description
//
// Start the event source that will start publishing events on its publication channel.
//
// # Implementation requirements & hints
//
// - The method must return an error if the source has already been started.
// - The method must return an error if the provided context has been canceled or has expired.
// - The method must return an error if the source has been stopped (no restart).
// - The method must close the publication channel.
//
// # Inputs
//
// - ctx: Context used for tracing purpose.
//
// # Return
//
// An error if the event source could not be started.
func (mock *EventSourceMock) Start(ctx context.Context) error {
args := mock.Called(ctx)
return args.Error(0)
}
// # Description
//
// Stop the event source and close the publication channel.
//
// # Implementation requirements & hints
//
// - The method must return an error if the source has not been started.
// - The method must return an error if the source has already been stopped.
// - The method must close the publication channel even if the underlying event source could
// not properly closed.
// - The closed publication channel must be kept: source must not be restarted (stale source).
//
// # Inputs
//
// - ctx: Context used for tracing purpose.
//
// # Return
//
// An error if the event source could not be closed.
func (mock *EventSourceMock) Stop(ctx context.Context) error {
args := mock.Called(ctx)
return args.Error(0)
}