forked from roadrunner-server/roadrunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol_test.go
46 lines (36 loc) · 1009 Bytes
/
protocol_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
package roadrunner
import (
"github.com/pkg/errors"
"github.com/spiral/goridge"
"github.com/stretchr/testify/assert"
"testing"
)
type relayMock struct {
error bool
payload string
}
func (r *relayMock) Send(data []byte, flags byte) (err error) {
if r.error {
return errors.New("send error")
}
return nil
}
func (r *relayMock) Receive() (data []byte, p goridge.Prefix, err error) {
return []byte(r.payload), goridge.NewPrefix().WithFlag(goridge.PayloadControl), nil
}
func (r *relayMock) Close() error {
return nil
}
func Test_Protocol_Errors(t *testing.T) {
err := sendPayload(&relayMock{}, make(chan int))
assert.Error(t, err)
}
func Test_Protocol_FetchPID(t *testing.T) {
pid, err := fetchPID(&relayMock{error: false, payload: "{\"pid\":100}"})
assert.NoError(t, err)
assert.Equal(t, 100, pid)
_, err = fetchPID(&relayMock{error: true, payload: "{\"pid\":100}"})
assert.Error(t, err)
_, err = fetchPID(&relayMock{error: false, payload: "{\"pid:100"})
assert.Error(t, err)
}