From dc3959e0dd803c30361cbf6697293db6090dad66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulko?= Date: Tue, 12 Mar 2024 16:02:43 +0100 Subject: [PATCH] Add ImageFilter API validations This adds tests related to kubebuilder validations of ImageFilter. --- ...neutronfilters_test.go => filters_test.go} | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) rename test/e2e/suites/apivalidations/{neutronfilters_test.go => filters_test.go} (79%) diff --git a/test/e2e/suites/apivalidations/neutronfilters_test.go b/test/e2e/suites/apivalidations/filters_test.go similarity index 79% rename from test/e2e/suites/apivalidations/neutronfilters_test.go rename to test/e2e/suites/apivalidations/filters_test.go index 59fb80e9fd..b4e256cff8 100644 --- a/test/e2e/suites/apivalidations/neutronfilters_test.go +++ b/test/e2e/suites/apivalidations/filters_test.go @@ -20,11 +20,12 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1" ) -var _ = Describe("Neutron filter API validations", func() { +var _ = Describe("Filter API validations", func() { var ( namespace *corev1.Namespace cluster *infrav1.OpenStackCluster @@ -173,4 +174,49 @@ var _ = Describe("Neutron filter API validations", func() { {Tags: []infrav1.NeutronTag{"foo", ""}}, }), ) + + const imageUUID = "5a78f794-cdc3-48d2-8d9f-0fd472fdd743" + + It("should not allow both ID and Name of ImageFilter to be set", func() { + By("Creating a machine") + machine.Spec.Image = infrav1.ImageFilter{ + ID: pointer.String(imageUUID), + Name: pointer.String("bar"), + } + Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "OpenStackMachine creation should fail") + }) + + It("should not allow both ID and Tags of ImageFilter to be set", func() { + By("Creating a machine") + machine.Spec.Image = infrav1.ImageFilter{ + ID: pointer.String(imageUUID), + Tags: []string{"bar", "baz"}, + } + Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "OpenStackMachine creation should fail") + }) + + It("should allow UUID ID of ImageFilter to be set", func() { + By("Creating a machine") + machine.Spec.Image = infrav1.ImageFilter{ + ID: pointer.String(imageUUID), + } + Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation should succeed") + }) + + It("should not allow non-UUID ID of ImageFilter to be set", func() { + By("Creating a machine") + machine.Spec.Image = infrav1.ImageFilter{ + ID: pointer.String("foo"), + } + Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "OpenStackMachine creation should fail") + }) + + It("should allow Name and Tags of ImageFilter to be set", func() { + By("Creating a machine") + machine.Spec.Image = infrav1.ImageFilter{ + Name: pointer.String("bar"), + Tags: []string{"bar", "baz"}, + } + Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation should succeed") + }) })