-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtopology_test.go
148 lines (109 loc) · 3.3 KB
/
topology_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package streams_test
import (
"testing"
"github.com/msales/streams/v6"
"github.com/stretchr/testify/assert"
)
func TestNewSourceNode(t *testing.T) {
n := streams.NewSourceNode("test")
assert.Equal(t, "test", n.Name())
}
func TestSourceNode_AddChild(t *testing.T) {
child := &streams.ProcessorNode{}
n := streams.SourceNode{}
n.AddChild(child)
assert.Len(t, n.Children(), 1)
assert.Equal(t, child, n.Children()[0])
}
func TestSourceNode_Children(t *testing.T) {
child := &streams.ProcessorNode{}
n := streams.SourceNode{}
n.AddChild(child)
children := n.Children()
assert.Len(t, children, 1)
assert.Equal(t, child, children[0])
}
func TestSourceNode_Processor(t *testing.T) {
n := streams.SourceNode{}
processor := n.Processor()
assert.Nil(t, processor)
}
func TestNewProcessorNode(t *testing.T) {
p := new(MockProcessor)
n := streams.NewProcessorNode("test", p)
assert.Equal(t, "test", n.Name())
}
func TestProcessorNode_AddChild(t *testing.T) {
child := &streams.ProcessorNode{}
n := streams.ProcessorNode{}
n.AddChild(child)
assert.Len(t, n.Children(), 1)
assert.Equal(t, child, n.Children()[0])
}
func TestProcessorNode_Children(t *testing.T) {
child := &streams.ProcessorNode{}
n := streams.ProcessorNode{}
n.AddChild(child)
children := n.Children()
assert.Len(t, children, 1)
assert.Equal(t, child, children[0])
}
func TestProcessorNode_Processor(t *testing.T) {
p := new(MockProcessor)
n := streams.NewProcessorNode("test", p)
processor := n.Processor()
assert.Exactly(t, p, processor)
}
func TestTopologyBuilder_AddSource(t *testing.T) {
s := new(MockSource)
tb := streams.NewTopologyBuilder()
n := tb.AddSource("test", s)
to, errs := tb.Build()
assert.Len(t, errs, 0)
assert.IsType(t, &streams.SourceNode{}, n)
assert.Equal(t, "test", n.(*streams.SourceNode).Name())
assert.Len(t, to.Sources(), 1)
assert.Equal(t, n, to.Sources()[s])
}
func TestTopologyBuilder_AddProcessor(t *testing.T) {
p := new(MockProcessor)
pn := &streams.ProcessorNode{}
tb := streams.NewTopologyBuilder()
n := tb.AddProcessor("test", p, []streams.Node{pn})
to, errs := tb.Build()
assert.Len(t, errs, 0)
assert.IsType(t, &streams.ProcessorNode{}, n)
assert.Equal(t, "test", n.(*streams.ProcessorNode).Name())
assert.Len(t, pn.Children(), 1)
assert.Equal(t, n, pn.Children()[0])
assert.Len(t, to.Processors(), 1)
assert.Equal(t, n, to.Processors()[0])
}
func TestTopologyBuilder_BuildChecksInspections(t *testing.T) {
tb := streams.NewTopologyBuilder()
n1 := tb.AddProcessor("1", new(MockCommitter), []streams.Node{})
n2 := tb.AddProcessor("1", new(MockProcessor), []streams.Node{n1})
_ = tb.AddProcessor("1", new(MockCommitter), []streams.Node{n2})
_ = tb.AddSource("src", new(MockSource))
_ = tb.AddSource("src", new(MockSource))
_, errs := tb.Build()
assert.Len(t, errs, 3)
}
func TestTopology_Sources(t *testing.T) {
s := new(MockSource)
tb := streams.NewTopologyBuilder()
sn := tb.AddSource("test", s)
to, _ := tb.Build()
sources := to.Sources()
assert.Len(t, sources, 1)
assert.Equal(t, sn, sources[s])
}
func TestTopology_Processors(t *testing.T) {
p := new(MockProcessor)
tb := streams.NewTopologyBuilder()
pn := tb.AddProcessor("test2", p, []streams.Node{})
to, _ := tb.Build()
processors := to.Processors()
assert.Len(t, processors, 1)
assert.Equal(t, pn, processors[0])
}