Skip to content

Commit 99e998e

Browse files
committed
fix tests
Signed-off-by: Britania Rodriguez Reyes <[email protected]>
1 parent eb10bb3 commit 99e998e

File tree

2 files changed

+22
-50
lines changed

2 files changed

+22
-50
lines changed

pkg/controllers/updaterun/stop.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ func (r *Reconciler) stopDeleteStage(
187187
klog.V(2).InfoS("The delete stage is stopping", "numberOfDeletingClusters", len(toBeDeletedBindings), "updateRun", updateRunRef)
188188
allDeletingClustersDeleted := true
189189
for _, clusterStatus := range updateRunStatus.DeletionStageStatus.Clusters {
190-
klog.InfoS("Checking deletion status of cluster in delete stage", "cluster", clusterStatus.ClusterName, "conditions", clusterStatus.Conditions, "updateRun", updateRunRef)
191190
if condition.IsConditionStatusTrue(meta.FindStatusCondition(clusterStatus.Conditions,
192191
string(placementv1beta1.ClusterUpdatingConditionStarted)), updateRun.GetGeneration()) && !condition.IsConditionStatusTrue(
193192
meta.FindStatusCondition(clusterStatus.Conditions, string(placementv1beta1.ClusterUpdatingConditionSucceeded)),
@@ -197,7 +196,7 @@ func (r *Reconciler) stopDeleteStage(
197196
}
198197
}
199198

200-
if allDeletingClustersDeleted || len(toBeDeletedBindings) == 0 {
199+
if allDeletingClustersDeleted {
201200
markStageUpdatingStopped(updateRunStatus.DeletionStageStatus, updateRun.GetGeneration())
202201
}
203202
return len(toBeDeletedBindings) == 0, nil

pkg/controllers/updaterun/stop_test.go

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"k8s.io/apimachinery/pkg/api/meta"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/runtime"
29-
"k8s.io/apimachinery/pkg/util/intstr"
3029
"sigs.k8s.io/controller-runtime/pkg/client"
3130
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3231

@@ -80,14 +79,6 @@ func TestStopUpdatingStage(t *testing.T) {
8079
},
8180
},
8281
},
83-
UpdateStrategySnapshot: &placementv1beta1.UpdateStrategySpec{
84-
Stages: []placementv1beta1.StageConfig{
85-
{
86-
Name: "test-stage",
87-
MaxConcurrency: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
88-
},
89-
},
90-
},
9182
},
9283
},
9384
bindings: nil,
@@ -132,14 +123,6 @@ func TestStopUpdatingStage(t *testing.T) {
132123
},
133124
},
134125
},
135-
UpdateStrategySnapshot: &placementv1beta1.UpdateStrategySpec{
136-
Stages: []placementv1beta1.StageConfig{
137-
{
138-
Name: "test-stage",
139-
MaxConcurrency: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
140-
},
141-
},
142-
},
143126
},
144127
},
145128
bindings: []placementv1beta1.BindingObj{
@@ -226,12 +209,8 @@ func TestStopUpdatingStage(t *testing.T) {
226209
tt.updateRun.Status.StagesStatus[0].Conditions,
227210
string(placementv1beta1.StageUpdatingConditionProgressing),
228211
)
229-
if progressingCond == nil {
230-
t.Errorf("stopUpdatingStage() missing progressing condition")
231-
} else {
232-
if diff := cmp.Diff(tt.wantProgressCond, *progressingCond, cmpOptions...); diff != "" {
233-
t.Errorf("stopUpdatingStage() status mismatch: (-want +got):\n%s", diff)
234-
}
212+
if diff := cmp.Diff(tt.wantProgressCond, *progressingCond, cmpOptions...); diff != "" {
213+
t.Errorf("stopUpdatingStage() status mismatch: (-want +got):\n%s", diff)
235214
}
236215
})
237216
}
@@ -246,8 +225,7 @@ func TestStopDeleteStage(t *testing.T) {
246225
updateRun *placementv1beta1.ClusterStagedUpdateRun
247226
toBeDeletedBindings []placementv1beta1.BindingObj
248227
wantFinished bool
249-
wantError bool
250-
wantAbortError bool
228+
wantError error
251229
wantProgressCond metav1.Condition
252230
}{
253231
{
@@ -266,7 +244,7 @@ func TestStopDeleteStage(t *testing.T) {
266244
},
267245
toBeDeletedBindings: []placementv1beta1.BindingObj{},
268246
wantFinished: true,
269-
wantError: false,
247+
wantError: nil,
270248
wantProgressCond: metav1.Condition{
271249
Type: string(placementv1beta1.StageUpdatingConditionProgressing),
272250
Status: metav1.ConditionFalse,
@@ -312,7 +290,7 @@ func TestStopDeleteStage(t *testing.T) {
312290
},
313291
},
314292
wantFinished: false,
315-
wantError: false,
293+
wantError: nil,
316294
wantProgressCond: metav1.Condition{
317295
Type: string(placementv1beta1.StageUpdatingConditionProgressing),
318296
Status: metav1.ConditionUnknown,
@@ -357,9 +335,8 @@ func TestStopDeleteStage(t *testing.T) {
357335
},
358336
},
359337
},
360-
wantFinished: false,
361-
wantError: true,
362-
wantAbortError: true,
338+
wantFinished: false,
339+
wantError: errors.New("the cluster `cluster-1` in the deleting stage is marked as deleting but its corresponding binding is not deleting"),
363340
wantProgressCond: metav1.Condition{
364341
Type: string(placementv1beta1.StageUpdatingConditionProgressing),
365342
Status: metav1.ConditionUnknown,
@@ -395,9 +372,8 @@ func TestStopDeleteStage(t *testing.T) {
395372
},
396373
},
397374
},
398-
wantFinished: false,
399-
wantError: false,
400-
wantAbortError: false,
375+
wantFinished: false,
376+
wantError: nil,
401377
wantProgressCond: metav1.Condition{
402378
Type: string(placementv1beta1.StageUpdatingConditionProgressing),
403379
Status: metav1.ConditionFalse,
@@ -462,7 +438,7 @@ func TestStopDeleteStage(t *testing.T) {
462438
},
463439
},
464440
wantFinished: false,
465-
wantError: false,
441+
wantError: nil,
466442
wantProgressCond: metav1.Condition{
467443
Type: string(placementv1beta1.StageUpdatingConditionProgressing),
468444
Status: metav1.ConditionUnknown,
@@ -483,28 +459,25 @@ func TestStopDeleteStage(t *testing.T) {
483459
t.Errorf("stopDeleteStage() finished = %v, want %v", gotFinished, tt.wantFinished)
484460
}
485461

486-
// Check error expectations.
487-
if tt.wantError {
488-
if gotErr == nil {
489-
t.Errorf("stopDeleteStage() error = nil, want error")
490-
} else if tt.wantAbortError && !errors.Is(gotErr, errStagedUpdatedAborted) {
491-
t.Errorf("stopDeleteStage() error = %v, want errStagedUpdatedAborted", gotErr)
462+
// Verify error expectation.
463+
if (tt.wantError != nil) != (gotErr != nil) {
464+
t.Fatalf("stopUpdatingStage() want error: %v, got error: %v", tt.wantError, gotErr)
465+
}
466+
467+
// Verify error message contains expected substring.
468+
if tt.wantError != nil && gotErr != nil {
469+
if !strings.Contains(gotErr.Error(), tt.wantError.Error()) {
470+
t.Fatalf("stopUpdatingStage() want error: %v, got error: %v", tt.wantError, gotErr)
492471
}
493-
} else if gotErr != nil {
494-
t.Errorf("stopDeleteStage() error = %v, want nil", gotErr)
495472
}
496473

497474
// Check stage status condition.
498475
progressingCond := meta.FindStatusCondition(
499476
tt.updateRun.Status.DeletionStageStatus.Conditions,
500477
string(placementv1beta1.StageUpdatingConditionProgressing),
501478
)
502-
if progressingCond == nil {
503-
t.Errorf("stopDeleteStage() missing progressing condition")
504-
} else {
505-
if diff := cmp.Diff(tt.wantProgressCond, *progressingCond, cmpOptions...); diff != "" {
506-
t.Errorf("stopDeleteStage() status mismatch: (-want +got):\n%s", diff)
507-
}
479+
if diff := cmp.Diff(tt.wantProgressCond, *progressingCond, cmpOptions...); diff != "" {
480+
t.Errorf("stopDeleteStage() status mismatch: (-want +got):\n%s", diff)
508481
}
509482
})
510483
}

0 commit comments

Comments
 (0)