Skip to content

Commit c25fdb9

Browse files
authored
Fix shaky tests (#451)
* Fix shaky tests Use komega's `Eventually()` to make sure the `Subnet`'s status was populated * Fix some linter issues
1 parent aa9d268 commit c25fdb9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
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 {

test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func GetProjectDir() (string, error) {
184184
if err != nil {
185185
return wd, fmt.Errorf("failed to get current working directory: %w", err)
186186
}
187-
wd = strings.Replace(wd, "/test/e2e", "", -1)
187+
wd = strings.ReplaceAll(wd, "/test/e2e", "")
188188
return wd, nil
189189
}
190190

0 commit comments

Comments
 (0)