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.
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("TestSubNoHeader 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("TestSubNoID 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("TestSubPlain 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("TestSubNoTwice CONNECT Failed: e:<%q> connresponse:<%q>\n",
129 conn
.ConnectResponse
)
133 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
134 sc
, e
= conn
.Subscribe(sh
)
136 t
.Fatalf("TestSubNoTwice[%d] SUBSCRIBE1, proto:[%s], channel is nil\n",
140 t
.Fatalf("TestSubNoTwice[%d] SUBSCRIBE1, proto:%s expected:%v got:%v\n",
141 ti
, tv
.proto
, tv
.exe1
, e
)
145 sc
, e
= conn
.Subscribe(sh
)
147 t
.Fatalf("TestSubNoTwice[%d] SUBSCRIBE2, proto:%s expected:%v got:%v\n",
148 ti
, tv
.proto
, tv
.exe2
, e
)
151 e
= conn
.Disconnect(empty_headers
)
152 checkDisconnectError(t
, e
)
155 log
.Printf("TestSubNoTwice %d tests complete.\n", len(subTwiceDataList
))
158 func TestSubRoundTrip(t
*testing
.T
) {
159 for ti
, tv
:= range subPlainDataList
{ // *NOTE* Use the PlainData table
162 ch
= headersProtocol(ch
, tv
.proto
)
163 conn
, e
= Connect(n
, ch
)
165 t
.Fatalf("TestSubRoundTrip CONNECT Failed: e:<%q> connresponse:<%q>\n",
167 conn
.ConnectResponse
)
169 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
172 msg
:= "SUBROUNDTRIP: " + tv
.proto
173 nh
:= Headers
{HK_DESTINATION
, sh
.Value(HK_DESTINATION
)}
174 e
= conn
.Send(nh
, msg
)
176 t
.Fatalf("TestSubRoundTrip[%d] SEND, proto:%s expected:%v got:%v\n",
177 ti
, tv
.proto
, nil, e
)
181 sc
, e
= conn
.Subscribe(sh
)
183 t
.Fatalf("TestSubRoundTrip[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
187 t
.Fatalf("TestSubRoundTrip[%d] SUBSCRIBE, proto:%s expected:%v got:%v\n",
188 ti
, tv
.proto
, tv
.exe1
, e
)
192 id
:= fmt
.Sprintf("TestSubRoundTrip[%d] RECEIVE, proto:%s", ti
, tv
.proto
)
193 checkReceivedMD(t
, conn
, sc
, id
)
194 if msg
!= md
.Message
.BodyString() {
195 t
.Fatalf("TestSubRoundTrip[%d] RECEIVE, proto:%s expected:%v got:%v\n",
196 ti
, tv
.proto
, msg
, md
.Message
.BodyString())
200 e
= conn
.Unsubscribe(sh
)
202 t
.Fatalf("TestSubRoundTrip[%d] UNSUBSCRIBE, proto:%s expected:%v got:%v\n",
203 ti
, tv
.proto
, tv
.exe2
, e
)
206 e
= conn
.Disconnect(empty_headers
)
207 checkDisconnectError(t
, e
)
210 log
.Printf("TestSubRoundTrip %d tests complete.\n", len(subPlainDataList
))
213 func TestSubAckModes(t
*testing
.T
) {
214 for ti
, tv
:= range subAckDataList
{
217 ch
= headersProtocol(ch
, tv
.proto
)
218 conn
, e
= Connect(n
, ch
)
220 t
.Fatalf("TestSubAckModes CONNECT Failed: e:<%q> connresponse:<%q>\n",
222 conn
.ConnectResponse
)
226 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
227 sc
, e
= conn
.Subscribe(sh
)
230 t
.Fatalf("TestSubAckModes[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
235 t
.Fatalf("TestSubAckModes[%d] SUBSCRIBE, proto:%s expected:%v got:%v\n",
236 ti
, tv
.proto
, tv
.exe
, e
)
239 e
= conn
.Disconnect(empty_headers
)
240 checkDisconnectError(t
, e
)
243 log
.Printf("TestSubAckModes %d tests complete.\n", len(subAckDataList
))