-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrouter_pipeline_test.go
161 lines (136 loc) · 4.55 KB
/
router_pipeline_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package goul_test
import (
"testing"
"time"
"github.com/hyeoncheon/goul"
"github.com/hyeoncheon/goul/adapters"
"github.com/hyeoncheon/goul/pipes"
"github.com/stretchr/testify/require"
)
func Test_Pipeline_1_Functions(t *testing.T) {
r := require.New(t)
var router goul.Router = &goul.Pipeline{Router: &goul.BaseRouter{}}
reader := &adapters.DummyAdapter{ID: "R-----", Adapter: &goul.BaseAdapter{}}
defer reader.Close()
writer := &adapters.DummyAdapter{ID: "-----W", Adapter: &goul.BaseAdapter{}}
defer writer.Close()
router.SetLogger(goul.NewLogger("debug"))
router.SetReader(reader)
router.SetWriter(writer)
router.AddPipe(&pipes.DummyPipe{ID: "-C----", Pipe: &goul.BasePipe{Mode: goul.ModeConverter}})
router.AddPipe(&pipes.DummyPipe{ID: "----R-", Pipe: &goul.BasePipe{Mode: goul.ModeReverter}})
control, done, err := router.Run()
r.NoError(err, "error: %v", err)
r.NotNil(control)
r.NotNil(done)
time.Sleep(1 * time.Second)
close(control)
message := <-done
r.Equal("message", message.String())
}
func Test_Pipeline_21_ErrorHandlingNoReaderWriter(t *testing.T) {
r := require.New(t)
var err error
var router goul.Router = &goul.Pipeline{Router: &goul.BaseRouter{}}
control, done, err := router.Run()
r.EqualError(err, goul.ErrRouterNoReaderOrWriter)
r.Nil(control)
r.Nil(done)
}
func Test_Pipeline_22_ErrorHandlingNoWriter(t *testing.T) {
r := require.New(t)
var err error
var router goul.Router = &goul.Pipeline{Router: &goul.BaseRouter{}}
err = router.SetReader(&goul.BaseAdapter{})
r.NoError(err)
control, done, err := router.Run()
r.EqualError(err, goul.ErrRouterNoReaderOrWriter)
r.Nil(control)
r.Nil(done)
}
func Test_Pipeline_23_ErrorHandlingNoReader(t *testing.T) {
r := require.New(t)
var err error
var router goul.Router = &goul.Pipeline{Router: &goul.BaseRouter{}}
err = router.SetWriter(&goul.BaseAdapter{})
r.NoError(err)
control, done, err := router.Run()
r.EqualError(err, goul.ErrRouterNoReaderOrWriter)
r.Nil(control)
r.Nil(done)
}
func Test_Pipeline_24_ErrorHandlingReadNotImpl(t *testing.T) {
r := require.New(t)
var err error
router := &goul.Pipeline{Router: &goul.BaseRouter{}}
err = router.SetReader(&goul.BaseAdapter{})
r.NoError(err)
err = router.SetWriter(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
control, done, err := router.Run() // run with unimplemented pipe
r.EqualError(err, goul.ErrAdapterReadNotImplemented)
r.Nil(control)
r.Nil(done)
}
func Test_Pipeline_25_ErrorHandlingWriteNotImpl(t *testing.T) {
r := require.New(t)
var err error
router := &goul.Pipeline{Router: &goul.BaseRouter{}}
err = router.SetReader(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
err = router.SetWriter(&goul.BaseAdapter{})
r.NoError(err)
control, done, err := router.Run() // run with unimplemented pipe
r.EqualError(err, goul.ErrAdapterWriteNotImplemented)
r.Nil(control)
r.Nil(done)
}
func Test_Pipeline_26_ErrorHandlingConvertNotImpl(t *testing.T) {
r := require.New(t)
var err error
router := &goul.Pipeline{Router: &goul.BaseRouter{}}
err = router.SetReader(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
err = router.SetWriter(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
err = router.AddPipe(&goul.BasePipe{Mode: goul.ModeConverter})
r.NoError(err)
control, done, err := router.Run() // run with unimplemented pipe
r.EqualError(err, goul.ErrPipeConvertNotImplemented)
r.Nil(control)
r.Nil(done)
r.Equal(1, len(router.GetPipes()))
}
func Test_Pipeline_27_ErrorHandlingRevertNotImpl(t *testing.T) {
r := require.New(t)
var err error
router := &goul.Pipeline{Router: &goul.BaseRouter{}}
err = router.SetReader(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
err = router.SetWriter(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
err = router.AddPipe(&goul.BasePipe{Mode: goul.ModeReverter})
r.NoError(err)
control, done, err := router.Run() // run with unimplemented pipe
r.EqualError(err, goul.ErrPipeRevertNotImplemented)
r.Nil(control)
r.Nil(done)
r.Equal(1, len(router.GetPipes()))
}
func Test_Pipeline_41_EmptyRouterAddPipe(t *testing.T) {
r := require.New(t)
var err error
router := &goul.Pipeline{}
err = router.AddPipe(&goul.BasePipe{Mode: goul.ModeReverter})
r.EqualError(err, "panic")
}
func Test_Pipeline_42_EmptyRouterRun(t *testing.T) {
r := require.New(t)
var err error
router := &goul.Pipeline{}
control, done, err := router.Run() // run with unimplemented pipe
r.EqualError(err, "panic")
r.Nil(control)
r.Nil(done)
r.Equal(0, len(router.GetPipes()))
}