Skip to content

Commit 8658528

Browse files
test: enforce strict error handling in MultigresCluster controller tests
Updates `TestMultigresClusterReconciler_Reconcile` to check all errors returned during test setup and validation phases. Previously, errors from client operations (e.g., `c.Create`, `c.Get`) or setup functions were sometimes ignored. This change ensures that any failure in test prerequisites or validation immediately fails the test using `t.Fatal` or `t.Fatalf`. This prevents silent failures where a test might technically "pass" despite the setup failing, and provides immediate, clear feedback when the test environment is not in the expected state.
1 parent 60b96bb commit 8658528

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
144144
validate: func(t *testing.T, c client.Client) {
145145
ctx := t.Context()
146146
updatedCluster := &multigresv1alpha1.MultigresCluster{}
147-
_ = c.Get(ctx, types.NamespacedName{Name: clusterName, Namespace: namespace}, updatedCluster)
147+
if err := c.Get(ctx, types.NamespacedName{Name: clusterName, Namespace: namespace}, updatedCluster); err != nil {
148+
t.Fatalf("failed to get updated cluster: %v", err)
149+
}
148150
if !controllerutil.ContainsFinalizer(updatedCluster, finalizerName) {
149151
t.Error("Finalizer was not added to Cluster")
150152
}
@@ -512,14 +514,20 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
512514
ObjectMeta: metav1.ObjectMeta{Name: clusterName + "-zone-a", Namespace: namespace, Labels: map[string]string{"multigres.com/cluster": clusterName}},
513515
Spec: multigresv1alpha1.CellSpec{Name: "zone-a"},
514516
}
515-
_ = c.Create(ctx, cell)
517+
if err := c.Create(ctx, cell); err != nil {
518+
t.Fatalf("failed to create cell: %v", err)
519+
}
516520
cell.Status.Conditions = []metav1.Condition{{Type: "Available", Status: metav1.ConditionTrue}}
517-
_ = c.Status().Update(ctx, cell)
521+
if err := c.Status().Update(ctx, cell); err != nil {
522+
t.Fatalf("failed to update cell status: %v", err)
523+
}
518524
},
519525
expectError: false,
520526
validate: func(t *testing.T, c client.Client) {
521527
cluster := &multigresv1alpha1.MultigresCluster{}
522-
_ = c.Get(t.Context(), types.NamespacedName{Name: clusterName, Namespace: namespace}, cluster)
528+
if err := c.Get(t.Context(), types.NamespacedName{Name: clusterName, Namespace: namespace}, cluster); err != nil {
529+
t.Fatalf("failed to get cluster: %v", err)
530+
}
523531
if !meta.IsStatusConditionTrue(cluster.Status.Conditions, "Available") {
524532
t.Error("Cluster should be available")
525533
}
@@ -1028,7 +1036,9 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
10281036
check := &multigresv1alpha1.MultigresCluster{}
10291037
err := baseClient.Get(t.Context(), types.NamespacedName{Name: tc.cluster.Name, Namespace: tc.cluster.Namespace}, check)
10301038
if apierrors.IsNotFound(err) {
1031-
_ = baseClient.Create(t.Context(), tc.cluster)
1039+
if err := baseClient.Create(t.Context(), tc.cluster); err != nil {
1040+
t.Fatalf("failed to create initial cluster: %v", err)
1041+
}
10321042
}
10331043
}
10341044

0 commit comments

Comments
 (0)