File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ package roadrunner
2
+
3
+ import (
4
+ "testing"
5
+ "github.com/spiral/goridge"
6
+ "github.com/stretchr/testify/assert"
7
+ "github.com/pkg/errors"
8
+ )
9
+
10
+ type relayMock struct {
11
+ error bool
12
+ payload string
13
+ }
14
+
15
+ func (r * relayMock ) Send (data []byte , flags byte ) (err error ) {
16
+ if r .error {
17
+ return errors .New ("send error" )
18
+ } else {
19
+ return nil
20
+ }
21
+ }
22
+
23
+ func (r * relayMock ) Receive () (data []byte , p goridge.Prefix , err error ) {
24
+ return []byte (r .payload ), goridge .NewPrefix ().WithFlag (goridge .PayloadControl ), nil
25
+ }
26
+
27
+ func (r * relayMock ) Close () error {
28
+ return nil
29
+ }
30
+
31
+ func Test_Protocol_Errors (t * testing.T ) {
32
+ err := sendPayload (& relayMock {}, make (chan int ))
33
+ assert .Error (t , err )
34
+ }
35
+
36
+ func Test_Protocol_FetchPID (t * testing.T ) {
37
+ pid , err := fetchPID (& relayMock {error : false , payload : "{\" pid\" :100}" })
38
+ assert .NoError (t , err )
39
+ assert .Equal (t , 100 , pid )
40
+
41
+ _ , err = fetchPID (& relayMock {error : true , payload : "{\" pid\" :100}" })
42
+ assert .Error (t , err )
43
+
44
+ _ , err = fetchPID (& relayMock {error : false , payload : "{\" pid:100" })
45
+ assert .Error (t , err )
46
+ }
You can’t perform that action at this time.
0 commit comments