-
Notifications
You must be signed in to change notification settings - Fork 244
/
client_gomq_test.go
65 lines (52 loc) · 1.96 KB
/
client_gomq_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
//go:build !goczmq
// +build !goczmq
package boomer
import (
"errors"
"github.com/myzhan/gomq/zmtp"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Test gomq client", func() {
It("test connect with error", func() {
client := newClient("mock:0.0.0.0", 1234, "testing")
MockGomqDealerInstance.SetConnectError(errors.New("connect error"))
defer MockGomqDealerInstance.SetConnectError(nil)
err := client.connect()
Expect(err).To(HaveOccurred())
})
It("test server send generic message", func() {
client := newClient("mock:0.0.0.0", 1234, "testing")
client.connect()
defer client.close()
pingMessage := newGenericMessage("ping", nil, "testing")
pingMessageInBytes, _ := pingMessage.serialize()
pongMessage := newGenericMessage("pong", nil, "testing")
pongMessageInBytes, _ := pongMessage.serialize()
client.sendChannel() <- pingMessage
Eventually(MockGomqDealerInstance.SendChannel()).Should(Receive(Equal(pingMessageInBytes)))
serverMessage := &zmtp.Message{
MessageType: zmtp.UserMessage,
Body: [][]byte{pongMessageInBytes},
}
MockGomqDealerInstance.RecvChannel() <- serverMessage
Eventually(client.recvChannel()).Should(Receive(Equal(pongMessage)))
})
It("test server send custom message", func() {
client := newClient("mock:0.0.0.0", 1234, "testing")
client.connect()
defer client.close()
pingMessage := newGenericMessage("ping", nil, "testing")
pingMessageInBytes, _ := pingMessage.serialize()
pongMessage := newCustomMessage("pong", int64(123), "testing")
pongMessageInBytes, _ := pongMessage.serialize()
client.sendChannel() <- pingMessage
Eventually(MockGomqDealerInstance.SendChannel()).Should(Receive(Equal(pingMessageInBytes)))
serverZmtpMessage := &zmtp.Message{
MessageType: zmtp.UserMessage,
Body: [][]byte{pongMessageInBytes},
}
MockGomqDealerInstance.RecvChannel() <- serverZmtpMessage
Eventually(client.recvChannel()).Should(Receive(Equal(pongMessage)))
})
})