-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrouter_test.go
95 lines (77 loc) · 2.49 KB
/
router_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
package goul_test
import (
"testing"
"github.com/hyeoncheon/goul"
"github.com/hyeoncheon/goul/adapters"
"github.com/stretchr/testify/require"
)
func Test_BaseRouter_1_Functions(t *testing.T) {
r := require.New(t)
var err error
var router goul.Router = &goul.BaseRouter{}
err = router.SetLogger(goul.NewLogger("debug"))
r.NoError(err, "couldn't run SetLogger")
err = router.SetReader(&goul.BaseAdapter{})
r.NoError(err, "couldn't run SetReader")
err = router.SetWriter(&goul.BaseAdapter{})
r.NoError(err, "couldn't run SetWriter")
err = router.AddPipe(&goul.BasePipe{}) // BaseRouter does not support
r.EqualError(err, goul.ErrRouterPipelineNotSupported)
pipes := router.GetPipes()
r.Equal(0, len(pipes))
control, done, err := router.Run()
r.EqualError(err, goul.ErrAdapterReadNotImplemented)
r.Nil(control)
r.Nil(done)
}
// Using DummyAdapter
func Test_BaseRouter_2_ErrorHandling(t *testing.T) {
r := require.New(t)
var err error
var router goul.Router
router = &goul.BaseRouter{}
_, _, err = router.Run() // run before set reader and writer
r.EqualError(err, goul.ErrRouterNoReaderOrWriter)
err = router.SetReader(&goul.BaseAdapter{})
r.NoError(err)
_, _, err = router.Run() // run before set writer
r.EqualError(err, goul.ErrRouterNoReaderOrWriter)
router = &goul.BaseRouter{}
err = router.SetWriter(&goul.BaseAdapter{})
r.NoError(err)
control, done, err := router.Run() // run before set reader
r.EqualError(err, goul.ErrRouterNoReaderOrWriter)
r.Nil(control)
r.Nil(done)
// Read of BaseAdapter does not implemented.
err = router.SetReader(&goul.BaseAdapter{})
r.NoError(err)
control, done, err = router.Run() // run after set reader and writer
r.EqualError(err, goul.ErrAdapterReadNotImplemented)
r.Nil(control)
r.Nil(done)
// Write of BaseAdapter does not implemented.
err = router.SetReader(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
control, done, err = router.Run()
r.EqualError(err, goul.ErrAdapterWriteNotImplemented)
r.Nil(control)
r.Nil(done)
}
// Using DummyAdapter
func Test_BaseRouter_3_Run(t *testing.T) {
r := require.New(t)
var err error
var router goul.Router = &goul.BaseRouter{}
err = router.SetWriter(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
err = router.SetReader(&adapters.DummyAdapter{Adapter: &goul.BaseAdapter{}})
r.NoError(err)
control, done, err := router.Run()
r.NoError(err)
r.NotNil(control)
r.NotNil(done)
close(control)
message := <-done
r.Equal("message", message.String())
}