@@ -11,6 +11,8 @@ package resource_test
1111
1212import (
1313 b64 "encoding/base64"
14+ "fmt"
15+
1416 . "github.com/onsi/ginkgo/v2"
1517 . "github.com/onsi/gomega"
1618 rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/v2/api/v1beta1"
@@ -100,6 +102,16 @@ var _ = Describe("DefaultUserSecret", func() {
100102 Expect (port ).To (BeEquivalentTo ("5672" ))
101103 })
102104
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+
103115 By ("creating a default_user.conf file that contains the correct sysctl config format to be parsed by RabbitMQ" , func () {
104116 defaultUserConf , ok := secret .Data ["default_user.conf" ]
105117 Expect (ok ).To (BeTrue (), "Failed to find a key \" default_user.conf\" in the generated Secret" )
@@ -167,18 +179,18 @@ var _ = Describe("DefaultUserSecret", func() {
167179 })
168180
169181 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 () {
173183 instance .Spec .TLS .SecretName = "tls-secret"
174184
175185 obj , err := defaultUserSecretBuilder .Build ()
176186 Expect (err ).NotTo (HaveOccurred ())
177187 secret = obj .(* corev1.Secret )
178188
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/" )))
182194 })
183195
184196 Context ("when MQTT, STOMP, streams, WebMQTT, and WebSTOMP are enabled" , func () {
@@ -338,6 +350,8 @@ var _ = Describe("DefaultUserSecret", func() {
338350 Expect (ok ).To (BeTrue ())
339351 Expect (port ).To (BeEquivalentTo ("5671" ))
340352
353+ Expect (secret .Data ).To (HaveKeyWithValue ("connection_string" , MatchRegexp ("amqps:.*:5671/" )))
354+
341355 port , ok = secret .Data ["mqtt-port" ]
342356 Expect (ok ).To (BeTrue ())
343357 Expect (port ).To (BeEquivalentTo ("8883" ))
0 commit comments