-
Notifications
You must be signed in to change notification settings - Fork 0
/
gorgeous_test.go
77 lines (58 loc) · 1.32 KB
/
gorgeous_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
package gorgeous
import (
"context"
"fmt"
"log"
"testing"
"time"
"git.verystar.cn/GaomingQian/gorgeous/provider"
"github.com/stretchr/testify/assert"
)
type fetcherDemo struct{}
func (f *fetcherDemo) Name() string {
return "fetcher demo"
}
func (f *fetcherDemo) Size() int {
return 1
}
func (f *fetcherDemo) Action() (interface{}, error) {
return "hello world", nil
}
func (f *fetcherDemo) Interval() time.Duration {
return 1 * time.Second
}
func (f *fetcherDemo) Close() error {
log.Println("fetcher is closed.")
return nil
}
type workerDemo struct{}
func (h *workerDemo) Name() string {
return "demo"
}
func (h *workerDemo) Size() int {
return 1
}
func (h *workerDemo) HandleData(data interface{}) (interface{}, error) {
log.Printf("got data: %+v", data)
return "data that pass to next worker", fmt.Errorf("some error: data = %+v", data)
}
func (h *workerDemo) Next() provider.IWorkHandler {
return nil
}
func (h *workerDemo) Close() error {
log.Println("worker is closed")
return nil
}
func Test_startTask(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
gor, err := New(ctx)
assert.Nil(t, err)
gor.Add("demo", &fetcherDemo{}, &workerDemo{})
var stop = func() {
cancel()
log.Printf("done")
}
if err := gor.Start(stop); err != nil {
log.Fatal("gorgeous start failed:", err)
}
}