forked from trustmaster/goflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory_test.go
59 lines (46 loc) · 1000 Bytes
/
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
package flow
import (
"testing"
)
// Tests run-time process creating with flow.Factory
func TestFactory(t *testing.T) {
procs := make(map[string]interface{})
procs["e1"] = Factory("echoer")
in, out := make(chan int), make(chan int)
e1 := procs["e1"].(*echoer)
e1.In = in
e1.Out = out
RunProc(procs["e1"])
for i := 0; i < 10; i++ {
in <- i
i2 := <-out
if i != i2 {
t.Errorf("%d != %d", i2, i)
}
}
// Shutdown proc
close(in)
}
type dummyNet struct {
Graph
}
// Tests connection between 2 processes created at run-time
func TestFactoryConnection(t *testing.T) {
net := new(dummyNet)
net.InitGraphState()
net.AddNew("echoer", "e1")
net.AddNew("echoer", "e2")
net.Connect("e1", "Out", "e2", "In")
net.MapInPort("In", "e1", "In")
net.MapOutPort("Out", "e2", "Out")
in, out := make(chan int), make(chan int)
net.SetInPort("In", in)
net.SetOutPort("Out", out)
RunNet(net)
in <- 123
i := <-out
close(in)
if i != 123 {
t.Errorf("Error: %d != 123", i)
}
}