-
Notifications
You must be signed in to change notification settings - Fork 1
/
options_test.go
49 lines (44 loc) · 1.82 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
package asyncp
import (
"context"
"testing"
"time"
"github.com/demdxx/asyncp/v2/monitor"
"github.com/demdxx/asyncp/v2/monitor/kvstorage"
"github.com/stretchr/testify/assert"
)
type dummyMetric struct{}
func (dummyMetric) RegisterApplication(appInfo *monitor.ApplicationInfo) error { return nil }
func (dummyMetric) DeregisterApplication() error { return nil }
func (dummyMetric) ReceiveEvent(event monitor.EventType) error { return nil }
func (dummyMetric) ExecuteTask(event monitor.EventType, execTime time.Duration) error { return nil }
func (dummyMetric) ExecuteFailoverTask(_ monitor.EventType, _ time.Duration) error { return nil }
func TestOptions(t *testing.T) {
var (
options Options
optionFnk = []Option{
WithMainExecContext(context.Background()),
WithPanicHandler(func(Task, Event, any) {}),
WithErrorHandler(func(Task, Event, error) {}),
WithContextWrapper(func(ctx context.Context) context.Context { return ctx }),
WithStreamResponseMap("item1", &testPublisher{name: "test-"}),
WithResponseFactory(NewMultistreamResponseFactory("item2", &testPublisher{name: "test2"})),
WithStreamResponsePublisher(&testPublisher{name: "test3"}),
WithMonitorDefaults("test", dummyMetric{}),
WithCluster("test", ClusterWithReader(&kvstorage.ClusterInfoReader{})),
WithEventAllocator(newDefaultEventAllocator()),
}
)
for _, opt := range optionFnk {
opt(&options)
}
assert.NotNil(t, options.MainExecContext)
assert.NotNil(t, options.PanicHandler)
assert.NotNil(t, options.ErrorHandler)
assert.NotNil(t, options.ContextWrapper)
assert.NotNil(t, options.ResponseFactory)
assert.NotNil(t, options.Cluster)
assert.NotNil(t, options.EventAllocator)
assert.NotNil(t, options._eventAllocator())
assert.NotNil(t, (&Options{})._eventAllocator())
}