Rework writer deadline handling.
[stompngo.git] / unsub_test.go
blob0726ac03a5f774a569df008b5bea99cf6c0c018b
1 //
2 // Copyright © 2011-2017 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)
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)
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.protocol = tv.proto // Cheat, fake all protocols
97 // SUBSCRIBE Phase (depending on test data)
98 if tv.subfirst {
99 // Do a real SUBSCRIBE
100 // sc, e = conn.Subscribe
101 sh := fixHeaderDest(tv.subh) // destination fixed if needed
102 sc, e = conn.Subscribe(sh)
103 if e == nil && sc == nil {
104 t.Fatalf("TestUnSubBool[%d] SUBSCRIBE proto:%s expected OK, got <%v> <%v>\n",
105 ti, e, sc)
107 if sc == nil {
108 t.Fatalf("TestUnSubBool[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
109 ti, tv.proto)
111 if e != tv.exe1 {
112 t.Fatalf("TestUnSubBool[%d] SUBSCRIBE NEQCHECK proto:%s expected:%v got:%q\n",
113 ti, tv.proto, tv.exe2, e)
117 //fmt.Printf("fs,unsubh: <%v>\n", tv.unsubh)
118 // UNSCRIBE Phase
119 sh := fixHeaderDest(tv.unsubh) // destination fixed if needed
120 e = conn.Unsubscribe(sh)
121 if e != tv.exe2 {
122 t.Fatalf("TestUnSubBool[%d] UNSUBSCRIBE NEQCHECK proto:%s expected:%v got:%q\n",
123 ti, tv.proto, tv.exe2, e)
127 checkReceived(t, conn)
128 e = conn.Disconnect(empty_headers)
129 checkDisconnectError(t, e)
130 _ = closeConn(t, n)
131 log.Printf("TestUnSubBool %d tests complete.\n", len(unsubBoolDataList))