2 // Copyright © 2011-2019 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.
28 func TestUnSubNoHeader(t
*testing
.T
) {
31 ch
= headersProtocol(ch
, SPL_10
) // To start
32 conn
, e
= Connect(n
, ch
)
34 t
.Fatalf("TestUnSubNoHeader CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
38 for ti
, tv
:= range unsubNoHeaderDataList
{
39 conn
.protocol
= tv
.proto
// Cheat, fake all protocols
40 e
= conn
.Unsubscribe(empty_headers
)
42 t
.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:nil\n",
46 t
.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:%q\n",
51 checkReceived(t
, conn
, false)
52 e
= conn
.Disconnect(empty_headers
)
53 checkDisconnectError(t
, e
)
55 log
.Printf("TestUnSubNoHeader %d tests complete.\n", len(subNoHeaderDataList
))
59 func TestUnSubNoID(t
*testing
.T
) {
62 ch
= headersProtocol(ch
, SPL_10
) // To start
63 conn
, e
= Connect(n
, ch
)
65 t
.Fatalf("TestUnSubNoID CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
69 for ti
, tv
:= range unsubNoHeaderDataList
{
70 conn
.protocol
= tv
.proto
// Cheat, fake all protocols
71 e
= conn
.Unsubscribe(empty_headers
)
73 t
.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:%q\n",
78 checkReceived(t
, conn
, false)
79 e
= conn
.Disconnect(empty_headers
)
80 checkDisconnectError(t
, e
)
82 log
.Printf("TestUnSubNoID %d tests complete.\n", len(unsubNoHeaderDataList
))
85 func TestUnSubBool(t
*testing
.T
) {
88 ch
= headersProtocol(ch
, SPL_10
) // To start
89 conn
, e
= Connect(n
, ch
)
91 t
.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e
,
95 for ti
, tv
:= range unsubBoolDataList
{
97 conn
.protocol
= tv
.proto
// Cheat, fake all protocols
98 conn
.protoLock
.Unlock()
100 // SUBSCRIBE Phase (depending on test data)
102 // Do a real SUBSCRIBE
103 // sc, e = conn.Subscribe
104 sh
:= fixHeaderDest(tv
.subh
) // destination fixed if needed
105 sc
, e
= conn
.Subscribe(sh
)
106 if e
== nil && sc
== nil {
107 t
.Fatalf("TestUnSubBool[%d] SUBSCRIBE proto:%s expected OK, got <%v> <%v>\n",
108 ti
, conn
.protocol
, e
, sc
)
111 t
.Fatalf("TestUnSubBool[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
115 t
.Fatalf("TestUnSubBool[%d] SUBSCRIBE NEQCHECK proto:%s expected:%v got:%q\n",
116 ti
, tv
.proto
, tv
.exe1
, e
)
120 //fmt.Printf("fs,unsubh: <%v>\n", tv.unsubh)
122 sh
:= fixHeaderDest(tv
.unsubh
) // destination fixed if needed
123 e
= conn
.Unsubscribe(sh
)
125 t
.Fatalf("TestUnSubBool[%d] UNSUBSCRIBE NEQCHECK proto:%s expected:%v got:%q\n",
126 ti
, tv
.proto
, tv
.exe2
, e
)
130 checkReceived(t
, conn
, true) // true for this test
131 _
= conn
.Disconnect(empty_headers
)
133 log
.Printf("TestUnSubBool %d tests complete.\n", len(unsubBoolDataList
))