summaryrefslogtreecommitdiff
path: root/ext/protocol_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ext/protocol_test.go')
-rw-r--r--ext/protocol_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/ext/protocol_test.go b/ext/protocol_test.go
new file mode 100644
index 00000000..f6410ef5
--- /dev/null
+++ b/ext/protocol_test.go
@@ -0,0 +1,46 @@
+package ext
+
+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)
+}