Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛issue-1737: Add unit tests for openstackmachine_webhook #2068

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions test/e2e/suites/apivalidations/openstackmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ var _ = Describe("OpenStackMachine API validations", func() {
namespace = createNamespace()
})

It("should allow the smallest permissible machine spec", func() {
Expect(k8sClient.Create(ctx, defaultMachine())).To(Succeed(), "OpenStackMachine creation should succeed")
It("should allow to create a machine with correct spec", func() {
machine := defaultMachine()

By("Creating the smallest permissible machine spec")
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation should succeed")

machine = defaultMachine()
machine.Spec.IdentityRef = &infrav1.OpenStackIdentityReference{Name: "foobar", CloudName: "staging"}

By("Creating a machine with spec.identityRef")
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation with spec.identityRef should succeed")
})

It("should only allow the providerID to be set once", func() {
Expand All @@ -65,6 +74,29 @@ var _ = Describe("OpenStackMachine API validations", func() {
Expect(k8sClient.Update(ctx, machine)).NotTo(Succeed(), "Updating providerID should fail")
})

It("should allow the identityRef to be set several times", func() {
machine := defaultMachine()

By("Creating a bare machine")
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation should succeed")

By("Setting the identityRef")
machine.Spec.IdentityRef = ptr.To(infrav1.OpenStackIdentityReference{Name: "foo", CloudName: "staging"})
Expect(k8sClient.Update(ctx, machine)).To(Succeed(), "Setting the identityRef should succeed")

By("Updating the identityRef.Name")
machine.Spec.IdentityRef = ptr.To(infrav1.OpenStackIdentityReference{Name: "bar", CloudName: "staging"})
Expect(k8sClient.Update(ctx, machine)).To(Succeed(), "Updating the identityRef.Name should succeed")

By("Updating the identityRef.CloudName")
machine.Spec.IdentityRef = ptr.To(infrav1.OpenStackIdentityReference{Name: "bar", CloudName: "production"})
Expect(k8sClient.Update(ctx, machine)).To(Succeed(), "Updating the identityRef.CloudName should succeed")

By("Clearing the identityRef")
machine.Spec.IdentityRef = nil
Expect(k8sClient.Update(ctx, machine)).To(Succeed(), "Clearing the identityRef should succeed")
})

It("should not allow server metadata to exceed 255 characters", func() {
machine := defaultMachine()

Expand Down Expand Up @@ -114,6 +146,28 @@ var _ = Describe("OpenStackMachine API validations", func() {
Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "Creating a machine with a zero size additional block device should fail")
})

It("should allow to create machine with spec.RootVolume and non-root device name in spec.AdditionalBlockDevices", func() {
machine := defaultMachine()
machine.Spec.RootVolume = &infrav1.RootVolume{SizeGiB: 50, BlockDeviceVolume: infrav1.BlockDeviceVolume{}}
machine.Spec.AdditionalBlockDevices = []infrav1.AdditionalBlockDevice{
{Name: "user", SizeGiB: 30, Storage: infrav1.BlockDeviceStorage{}},
}

By("Creating a machine with spec.RootVolume and non-root device name in spec.AdditionalBlockDevices")
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation with non-root device name in spec.AdditionalBlockDevices should succeed")
})

It("should not allow to create machine with spec.RootVolume and root device name in spec.AdditionalBlockDevices", func() {
machine := defaultMachine()
machine.Spec.RootVolume = &infrav1.RootVolume{SizeGiB: 50, BlockDeviceVolume: infrav1.BlockDeviceVolume{}}
machine.Spec.AdditionalBlockDevices = []infrav1.AdditionalBlockDevice{
{Name: "root", SizeGiB: 30, Storage: infrav1.BlockDeviceStorage{}},
}

By("Creating a machine with spec.RootVolume and root device name in spec.AdditionalBlockDevices")
Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "OpenStackMachine creation with root device name in spec.AdditionalBlockDevices should not succeed")
})

/* FIXME: These tests are failing
It("should not allow additional volume with empty name", func() {
machine.Spec.AdditionalBlockDevices = []infrav1.AdditionalBlockDevice{
Expand Down