2 // Copyright © 2011-2017 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.
27 func TestSubNoHeader(t
*testing
.T
) {
30 ch
= headersProtocol(ch
, SPL_10
) // Start with 1.0
31 conn
, e
= Connect(n
, ch
)
33 t
.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
37 for ti
, tv
:= range subNoHeaderDataList
{
38 conn
.protocol
= tv
.proto
// Cheat, fake all protocols
39 _
, e
= conn
.Subscribe(empty_headers
)
41 t
.Fatalf("TestSubNoHeader[%d] proto:%s expected:%v got:nil\n",
45 t
.Fatalf("TestSubNoHeader[%d] proto:%s expected:%v got:%v\n",
46 ti
, tv
.proto
, tv
.exe
, e
)
50 e
= conn
.Disconnect(empty_headers
)
51 checkDisconnectError(t
, e
)
53 log
.Printf("TestSubNoHeader %d tests complete.\n", len(subNoHeaderDataList
))
56 func TestSubNoID(t
*testing
.T
) {
59 ch
= headersProtocol(ch
, SPL_10
) // Start with 1.0
60 conn
, e
= Connect(n
, ch
)
62 t
.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
66 for ti
, tv
:= range subNoIDDataList
{
67 conn
.protocol
= tv
.proto
// Cheat, fake all protocols
68 ud
:= tdest(tv
.subh
.Value(HK_DESTINATION
))
69 _
, e
= conn
.Subscribe(Headers
{HK_DESTINATION
, ud
})
71 t
.Fatalf("TestSubNoID[%d] proto:%s expected:%v got:%v\n",
72 ti
, tv
.proto
, tv
.exe
, e
)
76 e
= conn
.Disconnect(empty_headers
)
77 checkDisconnectError(t
, e
)
79 log
.Printf("TestSubNoID %d tests complete.\n", len(subNoIDDataList
))
82 func TestSubPlain(t
*testing
.T
) {
83 for ti
, tv
:= range subPlainDataList
{
86 ch
= headersProtocol(ch
, tv
.proto
)
87 conn
, e
= Connect(n
, ch
)
89 t
.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
94 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
95 sc
, e
= conn
.Subscribe(sh
)
97 t
.Fatalf("TestSubPlain[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
101 t
.Fatalf("TestSubPlain[%d] SUBSCRIBE, proto:%s expected:%v got:%v\n",
102 ti
, tv
.proto
, tv
.exe1
, e
)
106 sh
= fixHeaderDest(tv
.unsubh
) // destination fixed if needed
107 e
= conn
.Unsubscribe(sh
)
109 t
.Fatalf("TestSubPlain[%d] UNSUBSCRIBE, proto:%s expected:%v got:%v\n",
110 ti
, tv
.proto
, tv
.exe2
, e
)
113 e
= conn
.Disconnect(empty_headers
)
114 checkDisconnectError(t
, e
)
117 log
.Printf("TestSubPlain %d tests complete.\n", len(subPlainDataList
))
120 func TestSubNoTwice(t
*testing
.T
) {
121 for ti
, tv
:= range subTwiceDataList
{
124 ch
= headersProtocol(ch
, tv
.proto
)
125 conn
, e
= Connect(n
, ch
)
127 t
.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
128 conn
.ConnectResponse
)
132 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
133 sc
, e
= conn
.Subscribe(sh
)
135 t
.Fatalf("TestSubNoTwice[%d] SUBSCRIBE1, proto:[%s], channel is nil\n",
139 t
.Fatalf("TestSubNoTwice[%d] SUBSCRIBE1, proto:%s expected:%v got:%v\n",
140 ti
, tv
.proto
, tv
.exe1
, e
)
144 sc
, e
= conn
.Subscribe(sh
)
146 t
.Fatalf("TestSubNoTwice[%d] SUBSCRIBE2, proto:%s expected:%v got:%v\n",
147 ti
, tv
.proto
, tv
.exe2
, e
)
150 e
= conn
.Disconnect(empty_headers
)
151 checkDisconnectError(t
, e
)
154 log
.Printf("TestSubNoTwice %d tests complete.\n", len(subTwiceDataList
))
157 func TestSubRoundTrip(t
*testing
.T
) {
158 for ti
, tv
:= range subPlainDataList
{ // *NOTE* Use the PlainData table
161 ch
= headersProtocol(ch
, tv
.proto
)
162 conn
, e
= Connect(n
, ch
)
164 t
.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
165 conn
.ConnectResponse
)
167 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
170 msg
:= "SUBROUNDTRIP: " + tv
.proto
171 nh
:= Headers
{HK_DESTINATION
, sh
.Value(HK_DESTINATION
)}
172 e
= conn
.Send(nh
, msg
)
174 t
.Fatalf("TestSubRoundTrip[%d] SEND, proto:%s expected:%v got:%v\n",
175 ti
, tv
.proto
, nil, e
)
179 sc
, e
= conn
.Subscribe(sh
)
181 t
.Fatalf("TestSubRoundTrip[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
185 t
.Fatalf("TestSubRoundTrip[%d] SUBSCRIBE, proto:%s expected:%v got:%v\n",
186 ti
, tv
.proto
, tv
.exe1
, e
)
190 id
:= fmt
.Sprintf("TestSubRoundTrip[%d] RECEIVE, proto:%s", ti
, tv
.proto
)
191 checkReceivedMD(t
, conn
, sc
, id
)
192 if msg
!= md
.Message
.BodyString() {
193 t
.Fatalf("TestSubRoundTrip[%d] RECEIVE, proto:%s expected:%v got:%v\n",
194 ti
, tv
.proto
, msg
, md
.Message
.BodyString())
198 e
= conn
.Unsubscribe(sh
)
200 t
.Fatalf("TestSubRoundTrip[%d] UNSUBSCRIBE, proto:%s expected:%v got:%v\n",
201 ti
, tv
.proto
, tv
.exe2
, e
)
204 e
= conn
.Disconnect(empty_headers
)
205 checkDisconnectError(t
, e
)
208 log
.Printf("TestSubRoundTrip %d tests complete.\n", len(subPlainDataList
))
211 func TestSubAckModes(t
*testing
.T
) {
212 for ti
, tv
:= range subAckDataList
{
215 ch
= headersProtocol(ch
, tv
.proto
)
216 conn
, e
= Connect(n
, ch
)
218 t
.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
219 conn
.ConnectResponse
)
223 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
224 sc
, e
= conn
.Subscribe(sh
)
227 t
.Fatalf("TestSubAckModes[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
232 t
.Fatalf("TestSubAckModes[%d] SUBSCRIBE, proto:%s expected:%v got:%v\n",
233 ti
, tv
.proto
, tv
.exe
, e
)
236 e
= conn
.Disconnect(empty_headers
)
237 checkDisconnectError(t
, e
)
240 log
.Printf("TestSubAckModes %d tests complete.\n", len(subAckDataList
))