Skip to content

Commit

Permalink
controller/test: adjust controller-test for new webhook
Browse files Browse the repository at this point in the history
Theoretically, we just setup the webhook and can use the webhook in our
controller test. Somehow related to WebhookInstallOptions it should
work. Except, I don't get it to work.

Instead, there are not webhook in this unit test. We however have them
in the "Webhook Suite", so there is that.

Instead, adjust the controller test for the webhook changes. Note that
this doesn't actually check the webhook, since it's not running in this
setup.
  • Loading branch information
thom311 committed Dec 2, 2024
1 parent 309613d commit a138b5a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions internal/controller/dpuoperatorconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

var (
testNamespace = "openshift-dpu-operator"
testDpuOperatorConfigName = "default"
testDpuOperatorConfigName = "dpu-operator-config"
testDpuOperatorConfigKind = "DpuOperatorConfig"
testDpuDaemonName = "dpu-daemon"
testNetworkFunctionNAD = "dpunfcni-conf"
Expand Down Expand Up @@ -217,7 +217,7 @@ var _ = Describe("Main Controller", Ordered, func() {
Context("When DpuOperatorConfig CR exists with host mode", func() {
BeforeAll(func() {
ns := dpuOperatorNameSpace()
cr = dpuOperatorCR("operator-config", "host", ns)
cr = dpuOperatorCR(testDpuOperatorConfigName, "host", ns)
createNameSpace(mgr.GetClient(), ns)
createDpuOperatorCR(mgr.GetClient(), cr)
})
Expand All @@ -231,9 +231,25 @@ var _ = Describe("Main Controller", Ordered, func() {
err := mgr.GetClient().Get(context.Background(), types.NamespacedName{Namespace: testNamespace, Name: testNetworkFunctionNAD}, &nad)
Expect(errors.IsNotFound(err)).To(BeTrue())
})
It("only DpuOperatorConfig \"openshift-dpu-operator/dpu-operator-config\" is allowed", func() {
ns := dpuOperatorNameSpace()
client := mgr.GetClient()

/* The CR already exists. Adding it again will fail. */
cr := dpuOperatorCR(testDpuOperatorConfigName, "host", ns)
err := client.Create(context.Background(), cr)
Expect(err).To(HaveOccurred())

cr2 := dpuOperatorCR("foo", "host", ns)
err2 := client.Create(context.Background(), cr2)
/* The validating webhook does not run in this setup. Otherwise we would
* expect creating this CR to fail. */
Expect(err2).NotTo(HaveOccurred())
deleteDpuOperatorCR(mgr.GetClient(), cr2)
})
AfterAll(func() {
ns := dpuOperatorNameSpace()
cr = dpuOperatorCR("operator-config", "host", ns)
cr = dpuOperatorCR(testDpuOperatorConfigName, "host", ns)
deleteDpuOperatorCR(mgr.GetClient(), cr)
})
})
Expand Down
2 changes: 1 addition & 1 deletion internal/testutils/test_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

var (
testNamespace = "openshift-dpu-operator"
testDpuOperatorConfigName = "default"
testDpuOperatorConfigName = "dpu-operator-config"
testDpuOperatorConfigKind = "DpuOperatorConfig"
testDpuDaemonName = "dpu-daemon"
testNetworkFunctionNAD = "dpunfcni-conf"
Expand Down

0 comments on commit a138b5a

Please sign in to comment.