-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathevent_store.go
53 lines (42 loc) · 1.11 KB
/
event_store.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
package mock
import (
"context"
"fmt"
"github.com/thomaspoignant/go-feature-flag/exporter"
)
const consumerNameError = "error"
type implMockEventStore[T exporter.ExportableEvent] struct {
store []T
}
func NewEventStore[T exporter.ExportableEvent]() exporter.EventStore[T] {
store := &implMockEventStore[T]{}
return store
}
func (e *implMockEventStore[T]) AddConsumer(_ string) {
// nothing to do
}
func (e *implMockEventStore[T]) Add(data T) {
e.store = append(e.store, data)
}
func (e *implMockEventStore[T]) ProcessPendingEvents(consumerID string,
processFunc func(context.Context, []T) error) error {
if consumerID == consumerNameError {
return fmt.Errorf("error")
}
if err := processFunc(context.TODO(), e.store); err != nil {
return err
}
return nil
}
func (e *implMockEventStore[T]) GetPendingEventCount(consumerName string) (int64, error) {
if consumerName == consumerNameError {
return 0, fmt.Errorf("error")
}
return int64(len(e.store)), nil
}
func (e *implMockEventStore[T]) GetTotalEventCount() int64 {
return int64(len(e.store))
}
func (e *implMockEventStore[T]) Stop() {
// nothing to do
}