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 TestUnSubNoHeader(t
*testing
.T
) {
30 ch
= headersProtocol(ch
, SPL_10
) // To start
31 conn
, e
= Connect(n
, ch
)
33 t
.Fatalf("TestUnSubNoHeader CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
37 for ti
, tv
:= range unsubNoHeaderDataList
{
38 conn
.protocol
= tv
.proto
// Cheat, fake all protocols
39 e
= conn
.Unsubscribe(empty_headers
)
41 t
.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:nil\n",
45 t
.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:%q\n",
50 checkReceived(t
, conn
, false)
51 e
= conn
.Disconnect(empty_headers
)
52 checkDisconnectError(t
, e
)
54 log
.Printf("TestUnSubNoHeader %d tests complete.\n", len(subNoHeaderDataList
))
58 func TestUnSubNoID(t
*testing
.T
) {
61 ch
= headersProtocol(ch
, SPL_10
) // To start
62 conn
, e
= Connect(n
, ch
)
64 t
.Fatalf("TestUnSubNoID CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
68 for ti
, tv
:= range unsubNoHeaderDataList
{
69 conn
.protocol
= tv
.proto
// Cheat, fake all protocols
70 e
= conn
.Unsubscribe(empty_headers
)
72 t
.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:%q\n",
77 checkReceived(t
, conn
, false)
78 e
= conn
.Disconnect(empty_headers
)
79 checkDisconnectError(t
, e
)
81 log
.Printf("TestUnSubNoID %d tests complete.\n", len(unsubNoHeaderDataList
))
84 func TestUnSubBool(t
*testing
.T
) {
87 ch
= headersProtocol(ch
, SPL_10
) // To start
88 conn
, e
= Connect(n
, ch
)
90 t
.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
94 for ti
, tv
:= range unsubBoolDataList
{
96 conn
.protocol
= tv
.proto
// Cheat, fake all protocols
97 conn
.protoLock
.Unlock()
99 // SUBSCRIBE Phase (depending on test data)
101 // Do a real SUBSCRIBE
102 // sc, e = conn.Subscribe
103 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
104 sc
, e
= conn
.Subscribe(sh
)
105 if e
== nil && sc
== nil {
106 t
.Fatalf("TestUnSubBool[%d] SUBSCRIBE proto:%s expected OK, got <%v> <%v>\n",
107 ti
, conn
.protocol
, e
, sc
)
110 t
.Fatalf("TestUnSubBool[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
114 t
.Fatalf("TestUnSubBool[%d] SUBSCRIBE NEQCHECK proto:%s expected:%v got:%q\n",
115 ti
, tv
.proto
, tv
.exe1
, e
)
119 //fmt.Printf("fs,unsubh: <%v>\n", tv.unsubh)
121 sh
:= fixHeaderDest(tv
.unsubh
) // destination fixed if needed
122 e
= conn
.Unsubscribe(sh
)
124 t
.Fatalf("TestUnSubBool[%d] UNSUBSCRIBE NEQCHECK proto:%s expected:%v got:%q\n",
125 ti
, tv
.proto
, tv
.exe2
, e
)
129 checkReceived(t
, conn
, true) // true for this test
130 e
= conn
.Disconnect(empty_headers
)
131 checkDisconnectError(t
, e
)
133 log
.Printf("TestUnSubBool %d tests complete.\n", len(unsubBoolDataList
))