@@ -11,6 +11,8 @@ package resource_test
11
11
12
12
import (
13
13
b64 "encoding/base64"
14
+ "fmt"
15
+
14
16
. "github.com/onsi/ginkgo/v2"
15
17
. "github.com/onsi/gomega"
16
18
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/v2/api/v1beta1"
@@ -100,6 +102,16 @@ var _ = Describe("DefaultUserSecret", func() {
100
102
Expect (port ).To (BeEquivalentTo ("5672" ))
101
103
})
102
104
105
+ By ("Setting a connection string" , func () {
106
+ Expect (secret .Data ).To (HaveKey ("username" ), "Failed to find a key \" username\" in the generated Secret" )
107
+ Expect (secret .Data ).To (HaveKey ("password" ), "Failed to find a key \" password\" in the generated Secret" )
108
+ Expect (secret .Data ).To (HaveKey ("host" ), "Failed to find a key \" host\" in the generated Secret" )
109
+ Expect (secret .Data ).To (HaveKey ("port" ), "Failed to find a key \" port\" in the generated Secret" )
110
+
111
+ expectedConnectionString := []byte (fmt .Sprintf ("amqp://%s:%s@%s:%s/" , secret .Data ["username" ], secret .Data ["password" ], secret .Data ["host" ], secret .Data ["port" ]))
112
+ Expect (secret .Data ).To (HaveKeyWithValue ("connection_string" , expectedConnectionString ))
113
+ })
114
+
103
115
By ("creating a default_user.conf file that contains the correct sysctl config format to be parsed by RabbitMQ" , func () {
104
116
defaultUserConf , ok := secret .Data ["default_user.conf" ]
105
117
Expect (ok ).To (BeTrue (), "Failed to find a key \" default_user.conf\" in the generated Secret" )
@@ -167,18 +179,18 @@ var _ = Describe("DefaultUserSecret", func() {
167
179
})
168
180
169
181
Context ("when TLS is enabled" , func () {
170
- It ("Uses the AMQPS port in the user secret" , func () {
171
- var port []byte
172
-
182
+ It ("Uses the AMQPS protocol in the user secret" , func () {
173
183
instance .Spec .TLS .SecretName = "tls-secret"
174
184
175
185
obj , err := defaultUserSecretBuilder .Build ()
176
186
Expect (err ).NotTo (HaveOccurred ())
177
187
secret = obj .(* corev1.Secret )
178
188
179
- port , ok := secret .Data ["port" ]
180
- Expect (ok ).To (BeTrue (), "Failed to find key \" port\" in the generated Secret" )
181
- Expect (port ).To (BeEquivalentTo ("5671" ))
189
+ By ("Setting the AMQPS port in the user secret" )
190
+ Expect (secret .Data ).To (HaveKeyWithValue ("port" , []byte ("5671" )))
191
+
192
+ By ("setting the connection string to use the AMQPS protocol" )
193
+ Expect (secret .Data ).To (HaveKeyWithValue ("connection_string" , MatchRegexp ("amqps:.*:5671/" )))
182
194
})
183
195
184
196
Context ("when MQTT, STOMP, streams, WebMQTT, and WebSTOMP are enabled" , func () {
@@ -338,6 +350,8 @@ var _ = Describe("DefaultUserSecret", func() {
338
350
Expect (ok ).To (BeTrue ())
339
351
Expect (port ).To (BeEquivalentTo ("5671" ))
340
352
353
+ Expect (secret .Data ).To (HaveKeyWithValue ("connection_string" , MatchRegexp ("amqps:.*:5671/" )))
354
+
341
355
port , ok = secret .Data ["mqtt-port" ]
342
356
Expect (ok ).To (BeTrue ())
343
357
Expect (port ).To (BeEquivalentTo ("8883" ))
0 commit comments