-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwindow_test.go
52 lines (40 loc) · 983 Bytes
/
window_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
package main
import (
"testing"
"time"
"github.com/patrobinson/go-fish/output"
)
type TestRule struct {
windowCounter int
}
func (r *TestRule) Init(...interface{}) error { return nil }
func (r *TestRule) Close() error { return nil }
func (r *TestRule) Process(interface{}) interface{} {
return "a"
}
func (r *TestRule) WindowInterval() int {
return 1
}
func (r *TestRule) String() string {
return "TestRule"
}
func (r *TestRule) Window() ([]output.OutputEvent, error) {
r.windowCounter++
return []output.OutputEvent{}, nil
}
func TestWindowManager(t *testing.T) {
testRule := &TestRule{}
outChan := make(chan interface{})
manager := &windowManager{
sinkChan: &outChan,
rule: testRule,
}
manager.windowRunner()
time.Sleep(1 * time.Second)
manager.windowRunner()
time.Sleep(1 * time.Second)
manager.windowRunner()
if testRule.windowCounter != 3 {
t.Errorf("Expected Window() to be called 3 times, called %d times", testRule.windowCounter)
}
}