diff options
author | Wolfy-J <[email protected]> | 2018-01-28 19:13:04 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-01-28 19:13:04 +0300 |
commit | 7fa0ea8e9b18697fe06673ba9c5f24f32b06afa2 (patch) | |
tree | 1f7d1e803f1ec03b84e4917e5e8137b0bf71749c /protocol_test.go | |
parent | f606426f00e9ad59f078474d4005ec55d1f3d3a9 (diff) |
protocol tests
Diffstat (limited to 'protocol_test.go')
-rw-r--r-- | protocol_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/protocol_test.go b/protocol_test.go new file mode 100644 index 00000000..5c4fb124 --- /dev/null +++ b/protocol_test.go @@ -0,0 +1,46 @@ +package roadrunner + +import ( + "testing" + "github.com/spiral/goridge" + "github.com/stretchr/testify/assert" + "github.com/pkg/errors" +) + +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") + } else { + 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) +} |