Skip to content

Commit

Permalink
better matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
hxyannay committed Sep 6, 2024
1 parent b14f82d commit 99f123a
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions internal/resource/default_user_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ var _ = Describe("DefaultUserSecret", func() {
var password []byte
var host []byte
var port []byte
var connection_string []byte
var ok bool

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

By("Setting a connection string", func() {
connection_string, ok = secret.Data["connection_string"]
Expect(ok).To(BeTrue(), "Failed to find a key \"connection_string\" in the generated Secret")
Expect(secret.Data).To(HaveKey("username"), "Failed to find a key \"username\" in the generated Secret")
Expect(secret.Data).To(HaveKey("password"), "Failed to find a key \"password\" in the generated Secret")
Expect(secret.Data).To(HaveKey("host"), "Failed to find a key \"host\" in the generated Secret")
Expect(secret.Data).To(HaveKey("port"), "Failed to find a key \"port\" in the generated Secret")

username, ok = secret.Data["username"]
Expect(ok).To(BeTrue(), "Failed to find a key \"username\" in the generated Secret")

password, ok = secret.Data["password"]
Expect(ok).To(BeTrue(), "Failed to find a key \"password\" in the generated Secret")

host, ok = secret.Data["host"]
Expect(ok).To(BeTrue(), "Failed to find a key \"host\" in the generated Secret")

port, ok = secret.Data["port"]
Expect(ok).To(BeTrue(), "Failed to find a key \"port\" in the generated Secret")

Expect(connection_string).To(BeEquivalentTo(fmt.Sprintf("amqp://%s:%s@%s:%s/", username, password, host, port)))
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"]))))
})

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

By("Setting the AMQPS port in the user secret", func() {
var port []byte
port, ok := secret.Data["port"]
Expect(ok).To(BeTrue(), "Failed to find key \"port\" in the generated Secret")
Expect(port).To(BeEquivalentTo("5671"))
Expect(secret.Data).To(HaveKeyWithValue("port", []byte("5671")))
})

By("setting the connection string to use the AMQPS protocol", func() {
var connection_string []byte
connection_string, ok := secret.Data["connection_string"]
Expect(ok).To(BeTrue(), "Failed to find key \"connection_string\" in the generated Secret")
Expect(connection_string).To(HavePrefix("amqps:"))
Expect(connection_string).To(HaveSuffix(":5671/"))
Expect(secret.Data).To(HaveKeyWithValue("connection_string", MatchRegexp("amqps:.*:5671/")))
})
})

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

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

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

0 comments on commit 99f123a

Please sign in to comment.