Skip to content

Commit

Permalink
Add test for default queue name injection (#155)
Browse files Browse the repository at this point in the history
* Add test for default queue name injection

* Check user-provided queue name is not overridden by default
  • Loading branch information
tardieu authored Jun 17, 2024
1 parent d123c5e commit 426cb39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions internal/webhook/appwrapper_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ var _ = Describe("AppWrapper Webhook Tests", func() {
Expect(k8sClient.Delete(ctx, aw)).To(Succeed())
})

It("Default queue name is set", func() {
aw := toAppWrapper(pod(100))

Expect(k8sClient.Create(ctx, aw)).To(Succeed())
Expect(aw.Labels[QueueNameLabel]).Should(BeIdenticalTo(defaultQueueName), "aw should be labeled with the default queue name")
Expect(k8sClient.Delete(ctx, aw)).To(Succeed())
})

It("Provided queue name is not overridden by default queue name", func() {
aw := toAppWrapper(pod(100))
aw.Labels = utilmaps.MergeKeepFirst(map[string]string{QueueNameLabel: userProvidedQueueName}, aw.Labels)

Expect(k8sClient.Create(ctx, aw)).To(Succeed())
Expect(aw.Labels[QueueNameLabel]).Should(BeIdenticalTo(userProvidedQueueName), "queue name should not be overridden")
Expect(k8sClient.Delete(ctx, aw)).To(Succeed())
})

It("User name and ID are set", func() {
aw := toAppWrapper(pod(100))
aw.Labels = utilmaps.MergeKeepFirst(map[string]string{AppWrapperUsernameLabel: "bad", AppWrapperUserIDLabel: "bad"}, aw.Labels)
Expand Down
6 changes: 5 additions & 1 deletion internal/webhook/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ var cancel context.CancelFunc

const limitedUserName = "limited-user"
const limitedUserID = "8da0fcfe-6d7f-4f44-b433-d91d22cc1b8c"
const defaultQueueName = "default-queue"
const userProvidedQueueName = "user-queue"

func TestControllers(t *testing.T) {
RegisterFailHandler(Fail)
Expand Down Expand Up @@ -157,7 +159,9 @@ var _ = BeforeSuite(func() {
})
Expect(err).NotTo(HaveOccurred())

err = (&AppWrapperWebhook{Config: config.NewAppWrapperConfig()}).SetupWebhookWithManager(mgr)
conf := config.NewAppWrapperConfig()
conf.QueueName = defaultQueueName // add default queue name
err = (&AppWrapperWebhook{Config: conf}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:webhook
Expand Down

0 comments on commit 426cb39

Please sign in to comment.