-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
105 lines (92 loc) · 2.25 KB
/
options_test.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
package eventx
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
func TestComputeCoreOptions(t *testing.T) {
logger, err := zap.NewDevelopment()
if err != nil {
panic(err)
}
table := []struct {
name string
opts eventxOptions
expected func(opts *eventxOptions)
}{
{
name: "default",
opts: computeOptions(),
expected: func(opts *eventxOptions) {},
},
{
name: "with-get-last-events-limit",
opts: computeOptions(WithGetLastEventsLimit(50)),
expected: func(opts *eventxOptions) {
opts.getLastEventsLimit = 50
},
},
{
name: "with-get-unprocessed-events-limit",
opts: computeOptions(WithGetUnprocessedEventsLimit(100)),
expected: func(opts *eventxOptions) {
opts.getUnprocessedEventsLimit = 100
},
},
{
name: "with-db-processor-retry-timer",
opts: computeOptions(WithDBProcessorRetryTimer(20 * time.Second)),
expected: func(opts *eventxOptions) {
opts.dbProcessorRetryTimer = 20 * time.Second
},
},
{
name: "with-core-stored-events-size",
opts: computeOptions(WithCoreStoredEventsSize(2000)),
expected: func(opts *eventxOptions) {
opts.coreStoredEventsSize = 2000
},
},
{
name: "with-db-processor-error-retry-timer",
opts: computeOptions(WithDBProcessorErrorRetryTimer(20 * time.Second)),
expected: func(opts *eventxOptions) {
opts.dbProcessorErrorRetryTimer = 20 * time.Second
},
},
{
name: "with-logger",
opts: computeOptions(WithLogger(logger)),
expected: func(opts *eventxOptions) {
opts.logger = logger
},
},
}
for _, tc := range table {
e := tc
t.Run(e.name, func(t *testing.T) {
t.Parallel()
opts := defaultOptions()
opts.errorLogger = nil
e.expected(&opts)
e.opts.errorLogger = nil
assert.Equal(t, opts, e.opts)
})
}
}
func TestComputeCoreOptions_ErrorLogger(t *testing.T) {
t.Run("normal", func(t *testing.T) {
var lastErr error
options := computeOptions(WithErrorLogger(func(err error) {
lastErr = err
}))
options.errorLogger(errors.New("some error"))
assert.Equal(t, errors.New("some error"), lastErr)
})
t.Run("do nothing", func(t *testing.T) {
options := computeOptions()
options.errorLogger(errors.New("some error"))
})
}