-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhub_options_test.go
87 lines (69 loc) · 2.34 KB
/
hub_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
package streams_test
import (
"testing"
"github.com/neutrinocorp/streams"
"github.com/stretchr/testify/assert"
)
func TestWithInstanceName(t *testing.T) {
hub := streams.NewHub()
assert.Equal(t, "com.streams", hub.InstanceName)
hub = streams.NewHub(
streams.WithInstanceName("org.neutrino"))
assert.Equal(t, "org.neutrino", hub.InstanceName)
}
func TestWithWriter(t *testing.T) {
hub := streams.NewHub()
assert.IsType(t, streams.NoopWriter, hub.Writer)
hub = streams.NewHub(
streams.WithWriter(streams.NoopWriter))
assert.IsType(t, streams.NoopWriter, hub.Writer)
}
func TestWithMarshaler(t *testing.T) {
hub := streams.NewHub()
assert.IsType(t, streams.JSONMarshaler{}, hub.Marshaler)
hub = streams.NewHub(
streams.WithMarshaler(streams.JSONMarshaler{}))
assert.IsType(t, streams.JSONMarshaler{}, hub.Marshaler)
}
func TestWithReader(t *testing.T) {
hub := streams.NewHub()
assert.Empty(t, hub.Reader)
hub = streams.NewHub(
streams.WithReader(listenerDriverNoop{}))
assert.IsType(t, listenerDriverNoop{}, hub.Reader)
}
func TestWithIDFactory(t *testing.T) {
hub := streams.NewHub()
assert.IsType(t, streams.UuidIdFactory, hub.IDFactory)
hub = streams.NewHub(
streams.WithIDFactory(streams.UuidIdFactory))
assert.IsType(t, streams.UuidIdFactory, hub.IDFactory)
}
func TestWithSchemaRegistry(t *testing.T) {
hub := streams.NewHub()
assert.Nil(t, hub.SchemaRegistry)
hub = streams.NewHub(
streams.WithSchemaRegistry(streams.NoopSchemaRegistry{}))
assert.IsType(t, streams.NoopSchemaRegistry{}, hub.SchemaRegistry)
}
func TestWithReaderBehaviours(t *testing.T) {
hub := streams.NewHub()
assert.NotNil(t, hub.ReaderBehaviours)
totalDefaultBehaviours := len(hub.ReaderBehaviours)
hub = streams.NewHub(
streams.WithReaderBehaviours(func(node *streams.ReaderNode, hub *streams.Hub,
next streams.ReaderHandleFunc) streams.ReaderHandleFunc {
return next
}))
// verify if no default behaviour was removed
assert.Equal(t, totalDefaultBehaviours+1, len(hub.ReaderBehaviours))
}
func TestWithReaderBaseOptions(t *testing.T) {
hub := streams.NewHub()
assert.NotNil(t, hub.ReaderBaseOptions)
totalDefaultOpts := len(hub.ReaderBaseOptions)
hub = streams.NewHub(
streams.WithReaderBaseOptions(streams.WithGroup("foo")))
// verify if no default behaviour was removed
assert.Equal(t, totalDefaultOpts+1, len(hub.ReaderBaseOptions))
}