-
Notifications
You must be signed in to change notification settings - Fork 29
/
unsub_test.go
134 lines (125 loc) · 3.67 KB
/
unsub_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// Copyright © 2011-2019 Guy M. Allard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package stompngo
import (
//"fmt"
"log"
//"os"
"testing"
//"time"
)
func TestUnSubNoHeader(t *testing.T) {
n, _ = openConn(t)
ch := login_headers
ch = headersProtocol(ch, SPL_10) // To start
conn, e = Connect(n, ch)
if e != nil {
t.Fatalf("TestUnSubNoHeader CONNECT Failed: e:<%q> connresponse:<%q>\n", e,
conn.ConnectResponse)
}
//
for ti, tv := range unsubNoHeaderDataList {
conn.protocol = tv.proto // Cheat, fake all protocols
e = conn.Unsubscribe(empty_headers)
if e == nil {
t.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:nil\n",
ti, sp, tv.exe)
}
if e != tv.exe {
t.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:%q\n",
ti, sp, tv.exe, e)
}
}
//
checkReceived(t, conn, false)
e = conn.Disconnect(empty_headers)
checkDisconnectError(t, e)
_ = closeConn(t, n)
log.Printf("TestUnSubNoHeader %d tests complete.\n", len(subNoHeaderDataList))
}
func TestUnSubNoID(t *testing.T) {
n, _ = openConn(t)
ch := login_headers
ch = headersProtocol(ch, SPL_10) // To start
conn, e = Connect(n, ch)
if e != nil {
t.Fatalf("TestUnSubNoID CONNECT Failed: e:<%q> connresponse:<%q>\n", e,
conn.ConnectResponse)
}
//
for ti, tv := range unsubNoHeaderDataList {
conn.protocol = tv.proto // Cheat, fake all protocols
e = conn.Unsubscribe(empty_headers)
if e != tv.exe {
t.Fatalf("TestUnSubNoHeader[%d] proto:%s expected:%q got:%q\n",
ti, sp, tv.exe, e)
}
}
//
checkReceived(t, conn, false)
e = conn.Disconnect(empty_headers)
checkDisconnectError(t, e)
_ = closeConn(t, n)
log.Printf("TestUnSubNoID %d tests complete.\n", len(unsubNoHeaderDataList))
}
func TestUnSubBool(t *testing.T) {
n, _ = openConn(t)
ch := login_headers
ch = headersProtocol(ch, SPL_10) // To start
conn, e = Connect(n, ch)
if e != nil {
t.Fatalf("CONNECT Failed: e:<%q> connresponse:<%q>\n", e,
conn.ConnectResponse)
}
//
for ti, tv := range unsubBoolDataList {
conn.protoLock.Lock()
conn.protocol = tv.proto // Cheat, fake all protocols
conn.protoLock.Unlock()
// SUBSCRIBE Phase (depending on test data)
if tv.subfirst {
// Do a real SUBSCRIBE
// sc, e = conn.Subscribe
sh := fixHeaderDest(tv.subh) // destination fixed if needed
sc, e = conn.Subscribe(sh)
if e == nil && sc == nil {
t.Fatalf("TestUnSubBool[%d] SUBSCRIBE proto:%s expected OK, got <%v> <%v>\n",
ti, conn.protocol, e, sc)
}
if sc == nil {
t.Fatalf("TestUnSubBool[%d] SUBSCRIBE, proto:[%s], channel is nil\n",
ti, tv.proto)
}
if e != tv.exe1 {
t.Fatalf("TestUnSubBool[%d] SUBSCRIBE NEQCHECK proto:%s expected:%v got:%q\n",
ti, tv.proto, tv.exe1, e)
}
}
//fmt.Printf("fs,unsubh: <%v>\n", tv.unsubh)
// UNSCRIBE Phase
sh := fixHeaderDest(tv.unsubh) // destination fixed if needed
e = conn.Unsubscribe(sh)
if e != tv.exe2 {
t.Fatalf("TestUnSubBool[%d] UNSUBSCRIBE NEQCHECK proto:%s expected:%v got:%q\n",
ti, tv.proto, tv.exe2, e)
}
}
//
checkReceived(t, conn, true) // true for this test
_ = conn.Disconnect(empty_headers)
_ = closeConn(t, n)
log.Printf("TestUnSubBool %d tests complete.\n", len(unsubBoolDataList))
}