Modification level bump.
[stompngo.git] / unsub_test.go
bloba0bf609503b1d97c9c23dcbfd54ea2040850f8fe
1 //
2 // Copyright © 2011-2018 Guy M. Allard
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
17 package stompngo
19 import (
20 //"fmt"
21 "log"
22 //"os"
23 "testing"
24 //"time"
27 func TestUnSubNoHeader(t *testing.T) {
28 n, _ = openConn(t)
29 ch := login_headers
30 ch = headersProtocol(ch, SPL_10) // To start
31 conn, e = Connect(n, ch)
32 if e != nil {
33 t.Fatalf("TestUnSubNoHeader CONNECT Failed: e:<%q> connresponse:<%q>\n", e,
34 conn.ConnectResponse)
37 for ti, tv := range unsubNoHeaderDataList {
38 conn.protocol = tv.proto // Cheat, fake all protocols
39 e = conn.Unsubscribe(empty_headers)
40 if e == nil {
41 t.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:nil\n",
42 ti, sp, tv.exe)
44 if e != tv.exe {
45 t.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:%q\n",
46 ti, sp, tv.exe, e)
50 checkReceived(t, conn, false)
51 e = conn.Disconnect(empty_headers)
52 checkDisconnectError(t, e)
53 _ = closeConn(t, n)
54 log.Printf("TestUnSubNoHeader %d tests complete.\n", len(subNoHeaderDataList))
58 func TestUnSubNoID(t *testing.T) {
59 n, _ = openConn(t)
60 ch := login_headers
61 ch = headersProtocol(ch, SPL_10) // To start
62 conn, e = Connect(n, ch)
63 if e != nil {
64 t.Fatalf("TestUnSubNoID CONNECT Failed: e:<%q> connresponse:<%q>\n", e,
65 conn.ConnectResponse)
68 for ti, tv := range unsubNoHeaderDataList {
69 conn.protocol = tv.proto // Cheat, fake all protocols
70 e = conn.Unsubscribe(empty_headers)
71 if e != tv.exe {
72 t.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:%q\n",
73 ti, sp, tv.exe, e)
77 checkReceived(t, conn, false)
78 e = conn.Disconnect(empty_headers)
79 checkDisconnectError(t, e)
80 _ = closeConn(t, n)
81 log.Printf("TestUnSubNoID %d tests complete.\n", len(unsubNoHeaderDataList))
84 func TestUnSubBool(t *testing.T) {
85 n, _ = openConn(t)
86 ch := login_headers
87 ch = headersProtocol(ch, SPL_10) // To start
88 conn, e = Connect(n, ch)
89 if e != nil {
90 t.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e,
91 conn.ConnectResponse)
94 for ti, tv := range unsubBoolDataList {
95 conn.protoLock.Lock()
96 conn.protocol = tv.proto // Cheat, fake all protocols
97 conn.protoLock.Unlock()
99 // SUBSCRIBE Phase (depending on test data)
100 if tv.subfirst {
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)
109 if sc == nil {
110 t.Fatalf("TestUnSubBool[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
111 ti, tv.proto)
113 if e != tv.exe1 {
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)
120 // UNSCRIBE Phase
121 sh := fixHeaderDest(tv.unsubh) // destination fixed if needed
122 e = conn.Unsubscribe(sh)
123 if e != tv.exe2 {
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)
132 _ = closeConn(t, n)
133 log.Printf("TestUnSubBool %d tests complete.\n", len(unsubBoolDataList))