Skip to content

Commit 1e0b60f

Browse files
authored
Merge pull request #2068 from MykolaRodin/main
🐛issue-1737: Add unit tests for openstackmachine_webhook
2 parents 64242f4 + 89d7fe6 commit 1e0b60f

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

test/e2e/suites/apivalidations/openstackmachine_test.go

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,17 @@ var _ = Describe("OpenStackMachine API validations", func() {
4646
namespace = createNamespace()
4747
})
4848

49-
It("should allow the smallest permissible machine spec", func() {
50-
Expect(k8sClient.Create(ctx, defaultMachine())).To(Succeed(), "OpenStackMachine creation should succeed")
49+
It("should allow to create a machine with correct spec", func() {
50+
machine := defaultMachine()
51+
52+
By("Creating the smallest permissible machine spec")
53+
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation should succeed")
54+
55+
machine = defaultMachine()
56+
machine.Spec.IdentityRef = &infrav1.OpenStackIdentityReference{Name: "foobar", CloudName: "staging"}
57+
58+
By("Creating a machine with spec.identityRef")
59+
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation with spec.identityRef should succeed")
5160
})
5261

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

77+
It("should allow the identityRef to be set several times", func() {
78+
machine := defaultMachine()
79+
80+
By("Creating a bare machine")
81+
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation should succeed")
82+
83+
By("Setting the identityRef")
84+
machine.Spec.IdentityRef = ptr.To(infrav1.OpenStackIdentityReference{Name: "foo", CloudName: "staging"})
85+
Expect(k8sClient.Update(ctx, machine)).To(Succeed(), "Setting the identityRef should succeed")
86+
87+
By("Updating the identityRef.Name")
88+
machine.Spec.IdentityRef = ptr.To(infrav1.OpenStackIdentityReference{Name: "bar", CloudName: "staging"})
89+
Expect(k8sClient.Update(ctx, machine)).To(Succeed(), "Updating the identityRef.Name should succeed")
90+
91+
By("Updating the identityRef.CloudName")
92+
machine.Spec.IdentityRef = ptr.To(infrav1.OpenStackIdentityReference{Name: "bar", CloudName: "production"})
93+
Expect(k8sClient.Update(ctx, machine)).To(Succeed(), "Updating the identityRef.CloudName should succeed")
94+
95+
By("Clearing the identityRef")
96+
machine.Spec.IdentityRef = nil
97+
Expect(k8sClient.Update(ctx, machine)).To(Succeed(), "Clearing the identityRef should succeed")
98+
})
99+
68100
It("should not allow server metadata to exceed 255 characters", func() {
69101
machine := defaultMachine()
70102

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

149+
It("should allow to create machine with spec.RootVolume and non-root device name in spec.AdditionalBlockDevices", func() {
150+
machine := defaultMachine()
151+
machine.Spec.RootVolume = &infrav1.RootVolume{SizeGiB: 50, BlockDeviceVolume: infrav1.BlockDeviceVolume{}}
152+
machine.Spec.AdditionalBlockDevices = []infrav1.AdditionalBlockDevice{
153+
{Name: "user", SizeGiB: 30, Storage: infrav1.BlockDeviceStorage{}},
154+
}
155+
156+
By("Creating a machine with spec.RootVolume and non-root device name in spec.AdditionalBlockDevices")
157+
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "OpenStackMachine creation with non-root device name in spec.AdditionalBlockDevices should succeed")
158+
})
159+
160+
It("should not allow to create machine with spec.RootVolume and root device name in spec.AdditionalBlockDevices", func() {
161+
machine := defaultMachine()
162+
machine.Spec.RootVolume = &infrav1.RootVolume{SizeGiB: 50, BlockDeviceVolume: infrav1.BlockDeviceVolume{}}
163+
machine.Spec.AdditionalBlockDevices = []infrav1.AdditionalBlockDevice{
164+
{Name: "root", SizeGiB: 30, Storage: infrav1.BlockDeviceStorage{}},
165+
}
166+
167+
By("Creating a machine with spec.RootVolume and root device name in spec.AdditionalBlockDevices")
168+
Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "OpenStackMachine creation with root device name in spec.AdditionalBlockDevices should not succeed")
169+
})
170+
117171
/* FIXME: These tests are failing
118172
It("should not allow additional volume with empty name", func() {
119173
machine.Spec.AdditionalBlockDevices = []infrav1.AdditionalBlockDevice{

0 commit comments

Comments
 (0)