Skip to content

Commit 99f123a

Browse files
committed
better matchers
1 parent b14f82d commit 99f123a

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

internal/resource/default_user_secret_test.go

+8-29
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ var _ = Describe("DefaultUserSecret", func() {
5757
var password []byte
5858
var host []byte
5959
var port []byte
60-
var connection_string []byte
6160
var ok bool
6261

6362
obj, err := defaultUserSecretBuilder.Build()
@@ -104,22 +103,12 @@ var _ = Describe("DefaultUserSecret", func() {
104103
})
105104

106105
By("Setting a connection string", func() {
107-
connection_string, ok = secret.Data["connection_string"]
108-
Expect(ok).To(BeTrue(), "Failed to find a key \"connection_string\" in the generated Secret")
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")
109110

110-
username, ok = secret.Data["username"]
111-
Expect(ok).To(BeTrue(), "Failed to find a key \"username\" in the generated Secret")
112-
113-
password, ok = secret.Data["password"]
114-
Expect(ok).To(BeTrue(), "Failed to find a key \"password\" in the generated Secret")
115-
116-
host, ok = secret.Data["host"]
117-
Expect(ok).To(BeTrue(), "Failed to find a key \"host\" in the generated Secret")
118-
119-
port, ok = secret.Data["port"]
120-
Expect(ok).To(BeTrue(), "Failed to find a key \"port\" in the generated Secret")
121-
122-
Expect(connection_string).To(BeEquivalentTo(fmt.Sprintf("amqp://%s:%s@%s:%s/", username, password, host, port)))
111+
Expect(secret.Data).To(HaveKeyWithValue("connection_string", []byte(fmt.Sprintf("amqp://%s:%s@%s:%s/", secret.Data["username"], secret.Data["password"], secret.Data["host"], secret.Data["port"]))))
123112
})
124113

125114
By("creating a default_user.conf file that contains the correct sysctl config format to be parsed by RabbitMQ", func() {
@@ -197,18 +186,11 @@ var _ = Describe("DefaultUserSecret", func() {
197186
secret = obj.(*corev1.Secret)
198187

199188
By("Setting the AMQPS port in the user secret", func() {
200-
var port []byte
201-
port, ok := secret.Data["port"]
202-
Expect(ok).To(BeTrue(), "Failed to find key \"port\" in the generated Secret")
203-
Expect(port).To(BeEquivalentTo("5671"))
189+
Expect(secret.Data).To(HaveKeyWithValue("port", []byte("5671")))
204190
})
205191

206192
By("setting the connection string to use the AMQPS protocol", func() {
207-
var connection_string []byte
208-
connection_string, ok := secret.Data["connection_string"]
209-
Expect(ok).To(BeTrue(), "Failed to find key \"connection_string\" in the generated Secret")
210-
Expect(connection_string).To(HavePrefix("amqps:"))
211-
Expect(connection_string).To(HaveSuffix(":5671/"))
193+
Expect(secret.Data).To(HaveKeyWithValue("connection_string", MatchRegexp("amqps:.*:5671/")))
212194
})
213195
})
214196

@@ -369,10 +351,7 @@ var _ = Describe("DefaultUserSecret", func() {
369351
Expect(ok).To(BeTrue())
370352
Expect(port).To(BeEquivalentTo("5671"))
371353

372-
connection_string, ok := secret.Data["connection_string"]
373-
Expect(ok).To(BeTrue(), "Failed to find key \"connection_string\" in the generated Secret")
374-
Expect(connection_string).To(HavePrefix("amqps:"))
375-
Expect(connection_string).To(HaveSuffix(":5671/"))
354+
Expect(secret.Data).To(HaveKeyWithValue("connection_string", MatchRegexp("amqps:.*:5671/")))
376355

377356
port, ok = secret.Data["mqtt-port"]
378357
Expect(ok).To(BeTrue())

0 commit comments

Comments
 (0)