Skip to content

Commit 083597e

Browse files
committed
Fix shaky tests
Use komega's `Eventually()` to make sure the `Subnet`'s status was populated
1 parent 7eb5102 commit 083597e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

internal/controller/subnet_controller_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"sigs.k8s.io/controller-runtime/pkg/client"
1515

1616
"github.com/ironcore-dev/ipam/api/ipam/v1alpha1"
17+
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
1718
)
1819

1920
var _ = Describe("Subnet controller", func() {
@@ -144,13 +145,14 @@ var _ = Describe("Subnet controller", func() {
144145
}).Should(BeTrue())
145146

146147
By("Subnet has updated status")
147-
Expect(createdSubnet.Status.Capacity.Value()).To(Equal(testCidr.AddressCapacity().Int64()))
148-
Expect(createdSubnet.Status.CapacityLeft.Value()).To(Equal(testCidr.AddressCapacity().Int64()))
149-
Expect(createdSubnet.Status.Locality).To(Equal(v1alpha1.LocalSubnetLocalityType))
150-
Expect(createdSubnet.Status.Vacant).To(HaveLen(1))
151-
Expect(createdSubnet.Status.Vacant[0].Equal(testCidr)).To(BeTrue())
152-
Expect(createdSubnet.Status.Type).To(Equal(v1alpha1.IPv4SubnetType))
153-
Expect(createdSubnet.Status.Message).To(BeZero())
148+
Eventually(Object(&createdSubnet)).Should(SatisfyAll(
149+
HaveField("Status.Capacity.Value()", testCidr.AddressCapacity().Int64()),
150+
HaveField("Status.CapacityLeft.Value()", testCidr.AddressCapacity().Int64()),
151+
HaveField("Status.Locality", v1alpha1.LocalSubnetLocalityType),
152+
HaveField("Status.Vacant", HaveLen(1)),
153+
HaveField("Status.Vacant", ContainElement(*testCidr)),
154+
HaveField("Status.Type", v1alpha1.IPv4SubnetType),
155+
HaveField("Status.Message", BeEmpty())))
154156

155157
By("Subnet CIDR is reserved in Network")
156158
Eventually(func() bool {

0 commit comments

Comments
 (0)