Skip to content

Commit 650ba81

Browse files
committed
Fix TestFinalizerAddition to exercise controller's Reconcile logic
Previously the test was manually adding finalizers using controllerutil.AddFinalizer instead of testing the actual controller logic. Now the test calls the controller's Reconcile method to properly exercise the finalizer addition logic as intended. Addresses: #97 (comment)
1 parent b6d8d81 commit 650ba81

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

internal/controller/finalizer_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
corev1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414
"k8s.io/apimachinery/pkg/types"
15+
ctrl "sigs.k8s.io/controller-runtime"
1516
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1617
)
1718

@@ -57,13 +58,17 @@ func TestFinalizerAddition(t *testing.T) {
5758
t.Error("Finalizer should not be present initially")
5859
}
5960

60-
// Simulate what happens in the reconcile loop when finalizer needs to be added
61-
if !controllerutil.ContainsFinalizer(workerDeploy, TemporalWorkerDeploymentFinalizer) {
62-
controllerutil.AddFinalizer(workerDeploy, TemporalWorkerDeploymentFinalizer)
63-
err := reconciler.Update(ctx, workerDeploy)
64-
if err != nil {
65-
t.Fatalf("Failed to add finalizer: %v", err)
66-
}
61+
// Exercise the controller's logic for adding finalizers by calling Reconcile
62+
req := ctrl.Request{
63+
NamespacedName: types.NamespacedName{
64+
Name: "test-worker",
65+
Namespace: "default",
66+
},
67+
}
68+
69+
_, err = reconciler.Reconcile(ctx, req)
70+
if err != nil {
71+
t.Fatalf("Reconcile failed: %v", err)
6772
}
6873

6974
// Fetch the updated resource

0 commit comments

Comments
 (0)