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.
24 Test suppress_content_length header.
26 func TestSuppressContentLength(t
*testing
.T
) {
27 for _
, sp
:= range Protocols() {
30 ch
= headersProtocol(ch
, sp
)
31 conn
, e
= Connect(n
, ch
)
33 t
.Fatalf("TestSuppressContentLength CONNECT Failed: e:<%q> connresponse:<%q>\n",
38 d
:= tdest("/queue/suppress.content.length")
40 sbh
:= Headers
{HK_DESTINATION
, d
, HK_ID
, id
}
41 sc
, e
= conn
.Subscribe(sbh
)
43 t
.Fatalf("TestSuppressContentLength Expected no subscribe error, got [%v]\n",
47 t
.Fatalf("TestSuppressContentLength Expected subscribe channel, got [nil]\n")
52 sh
:= Headers
{HK_DESTINATION
, d
, HK_SUPPRESS_CL
, "yes"}
53 for tn
, tv
:= range tsclData
{
55 e
= conn
.SendBytes(sh
, tv
.ba
)
57 t
.Fatalf("TestSuppressContentLength Expected no send error, got [%v]\n",
62 case v
= <-conn
.MessageData
:
63 t
.Fatalf("TestSuppressContentLength Expected no RECEIPT/ERROR error, got [%v]\n",
66 if tv
.wanted
!= string(v
.Message
.Body
) {
67 t
.Fatalf("TestSuppressContentLength Expected same data, tn:%d wanted[%v], got [%v]\n",
68 tn
, tv
.wanted
, string(v
.Message
.Body
))
72 // Finally Unsubscribe
73 uh
:= Headers
{HK_DESTINATION
, d
, HK_ID
, id
}
74 e
= conn
.Unsubscribe(uh
)
76 t
.Fatalf("TestSuppressContentLength Expected no unsubscribe error, got [%v]\n",
80 checkReceived(t
, conn
, false)
81 e
= conn
.Disconnect(empty_headers
)
82 checkDisconnectError(t
, e
)
88 Test suppress_content_type header.
90 func TestSuppressContentType(t
*testing
.T
) {
91 for _
, sp
:= range Protocols() {
94 ch
= headersProtocol(ch
, sp
)
95 conn
, e
= Connect(n
, ch
)
97 t
.Fatalf("TestSuppressContentType CONNECT Failed: e:<%q> connresponse:<%q>\n",
101 // l := log.New(os.Stdout, "TSCT", log.Ldate|log.Lmicroseconds)
105 d
:= tdest("/queue/suppress.content.type")
107 sbh
:= Headers
{HK_DESTINATION
, d
, HK_ID
, id
}
108 sc
, e
= conn
.Subscribe(sbh
)
110 t
.Fatalf("TestSuppressContentType Expected no subscribe error, got [%v]\n",
114 t
.Fatalf("TestSuppressContentType Expected subscribe channel, got [nil]\n")
120 for tn
, tv
:= range tsctData
{
122 sh
= Headers
{HK_DESTINATION
, d
, HK_SUPPRESS_CT
, "yes"}
124 // sh = Headers{HK_DESTINATION, d, HK_SUPPRESS_CT}
125 sh
= Headers
{HK_DESTINATION
, d
}
128 e
= conn
.Send(sh
, tv
.body
)
130 t
.Fatalf("TestSuppressContentType Expected no send error, got [%v]\n",
133 // fmt.Printf("SCT01 tn:%d sent:%s\n", tn, tv.body)
136 case v
= <-conn
.MessageData
:
137 t
.Fatalf("TestSuppressContentType Expected no RECEIPT/ERROR error, got [%v]\n",
140 _
, try
:= v
.Message
.Headers
.Contains(HK_CONTENT_TYPE
)
141 // fmt.Printf("DUMP: md:%#v\n", v)
143 if try
!= tv
.wanted
{
144 t
.Fatalf("TestSuppressContentType tn:%d wanted:%t got:%t\n",
149 // Finally Unsubscribe
150 uh
:= Headers
{HK_DESTINATION
, d
, HK_ID
, id
}
151 e
= conn
.Unsubscribe(uh
)
153 t
.Fatalf("TestSuppressContentType Expected no unsubscribe error, got [%v]\n",
157 checkReceived(t
, conn
, false)
158 e
= conn
.Disconnect(empty_headers
)
159 checkDisconnectError(t
, e
)