forked from trustmaster/goflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory_test.go
113 lines (96 loc) · 1.77 KB
/
factory_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
package goflow
import (
"testing"
)
func TestFactoryCreate(t *testing.T) {
f := NewFactory()
err := RegisterTestComponents(f)
if err != nil {
t.Error(err)
return
}
instance, err := f.Create("echo")
if err != nil {
t.Error(err)
return
}
c, ok := instance.(Component)
if !ok {
t.Errorf("%+v is not a Component", c)
return
}
_, err = f.Create("notfound")
if err == nil {
t.Errorf("Expected an error")
}
}
func TestFactoryRegistration(t *testing.T) {
f := NewFactory(FactoryConfig{
RegistryCapacity: 10,
})
if err := RegisterTestComponents(f); err != nil {
t.Error(err)
return
}
err := f.Register("echo", func() (interface{}, error) {
return new(echo), nil
})
if err == nil {
t.Errorf("Expected an error")
return
}
err = f.Annotate("notfound", Annotation{})
if err == nil {
t.Errorf("Expected an error")
return
}
err = f.Unregister("echo")
if err != nil {
t.Error(err)
return
}
err = f.Unregister("echo")
if err == nil {
t.Errorf("Expected an error")
return
}
}
func TestFactoryGraph(t *testing.T) {
f := NewFactory()
err := RegisterTestComponents(f)
if err != nil {
t.Error(err)
return
}
err = RegisterTestGraph(f)
if err != nil {
t.Error(err)
return
}
n := NewGraph()
if err = n.AddNew("de", "doubleEcho", f); err != nil {
t.Error(err)
return
}
if err = n.AddNew("e", "echo", f); err != nil {
t.Error(err)
return
}
if err = n.AddNew("notfound", "notfound", f); err == nil {
t.Errorf("Expected an error")
return
}
if err = n.Connect("de", "Out", "e", "In"); err != nil {
t.Error(err)
return
}
if err = n.MapInPort("In", "de", "In"); err != nil {
t.Error(err)
return
}
if err = n.MapOutPort("Out", "e", "Out"); err != nil {
t.Error(err)
return
}
testGraphWithNumberSequence(n, t)
}