Skip to content

Commit 2d9371f

Browse files
committed
Make the project tests more reliable
1 parent 71d02fa commit 2d9371f

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

test/e2e/project.go

+28-6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func ProjectSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
6767
if (err != nil) || (project == nil) {
6868
Skip("Failed to fetch project")
6969
}
70+
71+
// Initialize affinityIds to an empty slice to avoid nil checks
72+
affinityIds = make([]string, 0)
7073
})
7174

7275
It("Should create a cluster in a project", func() {
@@ -90,22 +93,41 @@ func ProjectSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
9093
WaitForMachineDeployments: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
9194
}, clusterResources)
9295

96+
// Ensure the cluster was created successfully before proceeding with checks
97+
Expect(clusterResources.Cluster).ToNot(BeNil(), "Cluster was not created successfully")
98+
99+
By("Checking affinity groups and VPC in project")
93100
csClient := CreateCloudStackClient(ctx, input.BootstrapClusterProxy.GetKubeconfigPath())
94-
affinityIds = CheckAffinityGroupInProject(csClient, clusterResources.Cluster.Name, "pro", projectName)
101+
102+
// Check affinity groups
103+
By(fmt.Sprintf("Checking affinity groups for cluster %s in project %s", clusterResources.Cluster.Name, projectName))
104+
tempAffinityIds := CheckAffinityGroupInProject(csClient, clusterResources.Cluster.Name, "pro", projectName)
105+
Expect(tempAffinityIds).ToNot(BeEmpty(), "No affinity groups found for cluster")
106+
affinityIds = tempAffinityIds
107+
108+
// Check VPC
109+
By(fmt.Sprintf("Checking if VPC %s exists in project %s", vpcName, projectName))
95110
exists, err := CheckVPCExistsInProject(csClient, vpcName, projectName)
96-
Expect(err).To(BeNil())
97-
Expect(exists).To(BeTrue())
111+
Expect(err).To(BeNil(), "Error checking VPC existence")
112+
Expect(exists).To(BeTrue(), fmt.Sprintf("VPC %s does not exist in project %s", vpcName, projectName))
98113
})
99114

100115
AfterEach(func() {
101116
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
102117
dumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
103118

104119
csClient := CreateCloudStackClient(ctx, input.BootstrapClusterProxy.GetKubeconfigPath())
105-
err := CheckAffinityGroupsDeletedInProject(csClient, affinityIds, projectName)
106-
if err != nil {
107-
Fail(err.Error())
120+
121+
// Only check for affinity group deletion if affinity groups were created
122+
if len(affinityIds) > 0 {
123+
err := CheckAffinityGroupsDeletedInProject(csClient, affinityIds, projectName)
124+
if err != nil {
125+
Fail(err.Error())
126+
}
127+
} else {
128+
By("Skipping affinity group deletion check as no affinity groups were created")
108129
}
130+
109131
By("PASSED!")
110132
})
111133
}

0 commit comments

Comments
 (0)