-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflowbase_test.go
51 lines (42 loc) · 998 Bytes
/
flowbase_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
package flowbase
import (
"fmt"
"testing"
)
func TestNetworkName(t *testing.T) {
wantName := "hey-ho"
n := NewBaseNetwork(wantName)
haveName := n.Name()
if haveName != wantName {
t.Fatalf("Have name %s but wanted %s", haveName, wantName)
}
}
func TestRun(t *testing.T) {
n := NewBaseNetwork("testrun-network")
hw := NewHelloWorldProc("hw")
n.Add(hw)
n.Run()
}
// ----------------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------------
func NewHelloWorldProc(name string) *HelloWorldProc {
return &HelloWorldProc{
BaseProcess{
name: name,
inPorts: make(map[string]*InPort),
outPorts: map[string]*OutPort{
"out": NewOutPort("hw"),
},
},
}
}
type HelloWorldProc struct {
BaseProcess
}
func (p *HelloWorldProc) Run() {
defer p.outPorts["hw"].Close()
for i := 1; i <= 10; i++ {
p.outPorts["hw"].Send(fmt.Sprintf("Hello world for the %d:th time", i))
}
}