Skip to content

Commit b94518a

Browse files
committed
Add ImageFilter API validations
This adds tests related to kubebuilder validations of ImageFilter.
1 parent ca48654 commit b94518a

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

test/e2e/suites/apivalidations/neutronfilters_test.go renamed to test/e2e/suites/apivalidations/filters_test.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import (
2020
. "github.com/onsi/ginkgo/v2"
2121
. "github.com/onsi/gomega"
2222
corev1 "k8s.io/api/core/v1"
23+
"k8s.io/utils/pointer"
2324

2425
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
2526
)
2627

27-
var _ = Describe("Neutron filter API validations", func() {
28+
var _ = Describe("Filter API validations", func() {
2829
var (
2930
namespace *corev1.Namespace
3031
cluster *infrav1.OpenStackCluster
@@ -173,4 +174,49 @@ var _ = Describe("Neutron filter API validations", func() {
173174
{Tags: []infrav1.NeutronTag{"foo", ""}},
174175
}),
175176
)
177+
178+
const imageUUID = "5a78f794-cdc3-48d2-8d9f-0fd472fdd743"
179+
180+
It("should not allow both ID and Name of ImageFilter to be set", func() {
181+
By("Creating a machine")
182+
machine.Spec.Image = infrav1.ImageFilter{
183+
ID: pointer.String(imageUUID),
184+
Name: pointer.String("bar"),
185+
}
186+
Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "OpenStackMachine creation should fail")
187+
})
188+
189+
It("should not allow both ID and Tags of ImageFilter to be set", func() {
190+
By("Creating a machine")
191+
machine.Spec.Image = infrav1.ImageFilter{
192+
ID: pointer.String(imageUUID),
193+
Tags: []string{"bar", "baz"},
194+
}
195+
Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "OpenStackMachine creation should fail")
196+
})
197+
198+
It("should allow UUID ID of ImageFilter to be set", func() {
199+
By("Creating a machine")
200+
machine.Spec.Image = infrav1.ImageFilter{
201+
ID: pointer.String(imageUUID),
202+
}
203+
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation should succeed")
204+
})
205+
206+
It("should not allow non-UUID ID of ImageFilter to be set", func() {
207+
By("Creating a machine")
208+
machine.Spec.Image = infrav1.ImageFilter{
209+
ID: pointer.String("foo"),
210+
}
211+
Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "OpenStackMachine creation should fail")
212+
})
213+
214+
It("should allow Name and Tags of ImageFilter to be set", func() {
215+
By("Creating a machine")
216+
machine.Spec.Image = infrav1.ImageFilter{
217+
Name: pointer.String("bar"),
218+
Tags: []string{"bar", "baz"},
219+
}
220+
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation should succeed")
221+
})
176222
})

0 commit comments

Comments
 (0)