2 // Copyright © 2011-2018 Guy M. Allard
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
24 ConnDisc Test: net.Conn.
26 func TestConnCDDiscNetconn(t
*testing
.T
) {
32 ConnDisc Test: stompngo.Connect.
34 func TestConnCDDisc(t
*testing
.T
) {
35 for _
, sp
:= range Protocols() {
38 ch
= headersProtocol(ch
, sp
)
39 conn
, e
= Connect(n
, ch
)
41 t
.Fatalf("TestConnCDDisc Expected no connect error, got [%v]\n", e
)
44 t
.Fatalf("TestConnCDDisc Expected a connection, got [nil]\n")
46 if conn
.ConnectResponse
.Command
!= CONNECTED
{
47 t
.Fatalf("TestConnCDDisc Expected command [%v], got [%v]\n", CONNECTED
,
48 conn
.ConnectResponse
.Command
)
51 t
.Fatalf("TestConnCDDisc Expected connected [true], got [false]\n")
53 if !conn
.Connected() {
54 t
.Fatalf("TestConnCDDisc Expected connected [true], got [false]\n")
57 if conn
.Session() == "" {
58 t
.Fatalf("TestConnCDDisc Expected connected session, got [default value]\n")
61 if conn
.SendTickerInterval() != 0 {
62 t
.Fatalf("TestConnCDDisc Expected zero SendTickerInterval, got [%v]\n",
63 conn
.SendTickerInterval())
65 if conn
.ReceiveTickerInterval() != 0 {
66 t
.Fatalf("TestConnCDDisc Expected zero ReceiveTickerInterval, got [%v]\n",
67 conn
.SendTickerInterval())
69 if conn
.SendTickerCount() != 0 {
70 t
.Fatalf("TestConnCDDisc Expected zero SendTickerCount, got [%v]\n",
71 conn
.SendTickerCount())
73 if conn
.ReceiveTickerCount() != 0 {
74 t
.Fatalf("TestConnCDDisc Expected zero ReceiveTickerCount, got [%v]\n",
75 conn
.SendTickerCount())
78 if conn
.FramesRead() != 1 {
79 t
.Fatalf("TestConnCDDisc Expected 1 frame read, got [%d]\n", conn
.FramesRead())
81 if conn
.BytesRead() <= 0 {
82 t
.Fatalf("TestConnCDDisc Expected non-zero bytes read, got [%d]\n", conn
.BytesRead())
84 if conn
.FramesWritten() != 1 {
85 t
.Fatalf("TestConnCDDisc Expected 1 frame written, got [%d]\n", conn
.FramesWritten())
87 if conn
.BytesWritten() <= 0 {
88 t
.Fatalf("ETestConnCDDisc xpected non-zero bytes written, got [%d]\n",
91 if conn
.Running().Nanoseconds() == 0 {
92 t
.Fatalf("TestConnCDDisc Expected non-zero runtime, got [0]\n")
95 checkReceived(t
, conn
, false)
96 e
= conn
.Disconnect(empty_headers
)
97 checkDisconnectError(t
, e
)
103 ConnDisc Test: stompngo.Disconnect with client bypassing a receipt.
105 func TestConnCDDiscNoDiscReceipt(t
*testing
.T
) {
106 for _
, sp
:= range Protocols() {
109 ch
= headersProtocol(ch
, sp
)
110 conn
, e
= Connect(n
, ch
)
112 t
.Fatalf("TestConnCDDiscNoDiscReceipt Expected no connect error, got [%v]\n", e
)
115 checkReceived(t
, conn
, false)
116 e
= conn
.Disconnect(NoDiscReceipt
)
117 checkDisconnectError(t
, e
)
119 t
.Fatalf("TestConnCDDiscNoDiscReceipt Expected no disconnect error, got [%v]\n", e
)
121 if conn
.DisconnectReceipt
.Message
.Command
!= "" {
122 t
.Fatalf("TestConnCDDiscNoDiscReceipt Expected no disconnect receipt command, got [%v]\n",
123 conn
.DisconnectReceipt
.Message
.Command
)
125 // NO DISCONNECT checks here
131 ConnDisc Test: stompngo.Disconnect with receipt requested.
133 func TestConnCDDiscStompDiscReceipt(t
*testing
.T
) {
134 for _
, sp
:= range Protocols() {
137 ch
= headersProtocol(ch
, sp
)
138 conn
, e
= Connect(n
, ch
)
140 t
.Fatalf("TestConnCDDiscStompDiscReceipt Expected no connect error, got [%v]\n",
144 checkReceived(t
, conn
, false)
145 e
= conn
.Disconnect(Headers
{HK_RECEIPT
, rid
})
148 t
.Fatalf("TestConnCDDiscStompDiscReceipt Expected no disconnect error, got [%v]\n",
151 if conn
.DisconnectReceipt
.Error
!= nil {
152 t
.Fatalf("TestConnCDDiscStompDiscReceipt Expected no receipt error, got [%v]\n",
153 conn
.DisconnectReceipt
.Error
)
155 md
:= conn
.DisconnectReceipt
.Message
156 irid
, ok
:= md
.Headers
.Contains(HK_RECEIPT_ID
)
158 t
.Fatalf("TestConnCDDiscStompDiscReceipt Expected receipt-id, not received\n")
161 t
.Fatalf("TestConnCDDiscStompDiscReceipt Expected receipt-id [%q], got [%q]\n",
164 // NO DISCONNECT checks here
170 ConnDisc Test: Body Length of CONNECTED response.
172 func TestConnCDBodyLen(t
*testing
.T
) {
173 for _
, sp
:= range Protocols() {
176 ch
= headersProtocol(ch
, sp
)
177 conn
, e
= Connect(n
, ch
)
179 t
.Fatalf("TestConnCDBodyLen Expected no connect error, got [%v]\n", e
)
181 if len(conn
.ConnectResponse
.Body
) != 0 {
182 t
.Fatalf("TestConnCDBodyLen Expected body length 0, got [%v]\n",
183 len(conn
.ConnectResponse
.Body
))
185 e
= conn
.Disconnect(empty_headers
)
187 t
.Fatalf("TestConnCDBodyLen Expected no disconnect error, got [%v]\n", e
)
194 Conn11 Test: Test Protocol level
196 func TestConnCDProto(t
*testing
.T
) {
197 for _
, sp
:= range Protocols() {
200 ch
= headersProtocol(ch
, sp
)
201 conn
, e
= Connect(n
, ch
)
203 t
.Fatalf("TestConnCDProto Expected no connect error, got [%v]\n", e
)
205 if conn
.Protocol() != sp
{
206 t
.Fatalf("TestConnCDProto Expected protocol %v, got [%v]\n", sp
, conn
.Protocol())
208 checkReceived(t
, conn
, false)
209 e
= conn
.Disconnect(empty_headers
)
211 t
.Fatalf("TestConnCDProto Expected no disconnect error, got [%v]\n", e
)
218 ConnReceipt Test: Test receipt not allowed on connect.
220 func TestConnCDReceipt(t
*testing
.T
) {
221 for _
, sp
:= range Protocols() {
224 ch
= headersProtocol(ch
, sp
)
225 ch
= ch
.Add(HK_RECEIPT
, "abcd1234")
226 _
, e
= Connect(n
, ch
)
228 t
.Fatalf("TestConnCDReceipt Expected connect error, got nil\n")
231 t
.Fatalf("TestConnCDReceipt Expected [%v], got [%v]\n", ENORECPT
, e
)
233 // No DISCONNECT checks for this test.
239 ConnDisc Test: ECONBAD
241 func TestConnCDEconBad(t
*testing
.T
) {
242 for _
, sp
:= range Protocols() {
245 ch
= headersProtocol(ch
, sp
)
246 conn
, e
= Connect(n
, ch
)
248 t
.Fatalf("TestConnCDEconBad Expected no connect error, got [%v]\n", e
)
250 checkReceived(t
, conn
, false)
251 e
= conn
.Disconnect(empty_headers
)
253 t
.Fatalf("TestConnCDEconBad Expected no disconnect error, got [%v]\n", e
)
257 e
= conn
.Abort(empty_headers
)
259 t
.Fatalf("TestConnCDEconBad Abort expected [%v] got [%v]\n", ECONBAD
, e
)
261 e
= conn
.Ack(empty_headers
)
263 t
.Fatalf("TestConnCDEconBad Ack expected [%v] got [%v]\n", ECONBAD
, e
)
265 e
= conn
.Begin(empty_headers
)
267 t
.Fatalf("TestConnCDEconBad Begin expected [%v] got [%v]\n", ECONBAD
, e
)
269 e
= conn
.Commit(empty_headers
)
271 t
.Fatalf("TestConnCDEconBad Commit expected [%v] got [%v]\n", ECONBAD
, e
)
273 e
= conn
.Nack(empty_headers
)
275 t
.Fatalf("TestConnCDEconBad Nack expected [%v] got [%v]\n", ECONBAD
, e
)
277 e
= conn
.Send(empty_headers
, "")
279 t
.Fatalf("TestConnCDEconBad Send expected [%v] got [%v]\n", ECONBAD
, e
)
281 _
, e
= conn
.Subscribe(empty_headers
)
283 t
.Fatalf("TestConnCDEconBad Subscribe expected [%v] got [%v]\n", ECONBAD
, e
)
285 e
= conn
.Unsubscribe(empty_headers
)
287 t
.Fatalf("TestConnCDEconBad Unsubscribe expected [%v] got [%v]\n", ECONBAD
, e
)
293 ConnDisc Test: ECONBAD
295 func TestConnCDEconDiscDone(t
*testing
.T
) {
296 for _
, sp
:= range Protocols() {
299 ch
= headersProtocol(ch
, sp
)
300 conn
, e
= Connect(n
, ch
)
302 t
.Fatalf("TestConnCDEconDiscDone Expected no connect error, got [%v]\n", e
)
304 e
= conn
.Disconnect(empty_headers
)
306 t
.Fatalf("TestConnCDEconDiscDone Expected no disconnect error, got [%v]\n", e
)
310 e
= conn
.Disconnect(empty_headers
)
312 t
.Fatalf("TestConnCDEconDiscDone Previous disconnect expected [%v] got [%v]\n", ECONBAD
, e
)
318 ConnDisc Test: setProtocolLevel
320 func TestConnCDCDSetProtocolLevel(t
*testing
.T
) {
321 for _
, sp
:= range Protocols() {
324 ch
= headersProtocol(ch
, sp
)
325 conn
, e
= Connect(n
, ch
)
327 t
.Fatalf("TestConnCDCDSetProtocolLevel Expected no connect error, got [%v]\n", e
)
329 for i
, v
:= range verChecks
{
330 conn
.protocol
= SPL_10
// reset
331 e
= conn
.setProtocolLevel(v
.ch
, v
.sh
)
333 t
.Fatalf("TestConnCDCDSetProtocolLevel Verdata Item [%d], expected [%v], got [%v]\n", i
, v
.e
, e
)
337 checkReceived(t
, conn
, false)
338 e
= conn
.Disconnect(empty_headers
)
339 checkDisconnectError(t
, e
)
345 ConnDisc Test: connRespData
347 func TestConnCDRespData(t
*testing
.T
) {
348 for _
, sp
:= range Protocols() {
351 ch
= headersProtocol(ch
, sp
)
352 conn
, e
= Connect(n
, ch
)
354 t
.Fatalf("TestConnCDRespData Expected no connect error, got [%v]\n", e
)
356 for i
, f
:= range frames
{
357 _
, e
= connectResponse(f
.data
)
359 t
.Fatalf("TestConnCDRespData Index [%v], expected [%v], got [%v]\n", i
, f
.resp
, e
)
362 checkReceived(t
, conn
, false)
363 e
= conn
.Disconnect(empty_headers
)
364 checkDisconnectError(t
, e
)