Skip to content

Commit 7a2f582

Browse files
author
Arvind Thirumurugan
committed
add UT
Signed-off-by: Arvind Thirumurugan <[email protected]>
1 parent 5522376 commit 7a2f582

File tree

1 file changed

+70
-6
lines changed

1 file changed

+70
-6
lines changed

pkg/controllers/updaterun/execution_test.go

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package updaterun
1919
import (
2020
"context"
2121
"errors"
22-
"fmt"
2322
"strings"
2423
"testing"
2524
"time"
@@ -510,7 +509,7 @@ func TestExecuteUpdatingStage_Error(t *testing.T) {
510509
},
511510
interceptorFunc: &interceptor.Funcs{
512511
Update: func(ctx context.Context, client client.WithWatch, obj client.Object, opts ...client.UpdateOption) error {
513-
return fmt.Errorf("simulated update error")
512+
return errors.New("simulated update error")
514513
},
515514
},
516515
wantErr: errors.New("simulated update error"),
@@ -630,7 +629,7 @@ func TestExecuteUpdatingStage_Error(t *testing.T) {
630629
},
631630
interceptorFunc: &interceptor.Funcs{
632631
Update: func(ctx context.Context, client client.WithWatch, obj client.Object, opts ...client.UpdateOption) error {
633-
return fmt.Errorf("failed to update binding state")
632+
return errors.New("failed to update binding state")
634633
},
635634
},
636635
wantErr: errors.New("failed to update binding state"),
@@ -686,8 +685,7 @@ func TestExecuteUpdatingStage_Error(t *testing.T) {
686685
Type: string(placementv1beta1.ResourceBindingRolloutStarted),
687686
Status: metav1.ConditionTrue,
688687
ObservedGeneration: 1, // Old generation - needs update.
689-
Reason: "RolloutStarted",
690-
Message: "Rollout started",
688+
Reason: condition.RolloutStartedReason,
691689
},
692690
},
693691
},
@@ -696,12 +694,78 @@ func TestExecuteUpdatingStage_Error(t *testing.T) {
696694
interceptorFunc: &interceptor.Funcs{
697695
SubResourceUpdate: func(ctx context.Context, client client.Client, subResourceName string, obj client.Object, opts ...client.SubResourceUpdateOption) error {
698696
// Fail the status update for rolloutStarted.
699-
return fmt.Errorf("failed to update binding rolloutStarted status")
697+
return errors.New("failed to update binding rolloutStarted status")
700698
},
701699
},
702700
wantErr: errors.New("failed to update binding rolloutStarted status"),
703701
expectWaitTime: 0,
704702
},
703+
{
704+
name: "binding synced, bound, rolloutStarted true, but binding has failed condition",
705+
updateRun: &placementv1beta1.ClusterStagedUpdateRun{
706+
ObjectMeta: metav1.ObjectMeta{
707+
Name: "test-update-run",
708+
Generation: 1,
709+
},
710+
Spec: placementv1beta1.UpdateRunSpec{
711+
PlacementName: "test-placement",
712+
ResourceSnapshotIndex: "1",
713+
},
714+
Status: placementv1beta1.UpdateRunStatus{
715+
StagesStatus: []placementv1beta1.StageUpdatingStatus{
716+
{
717+
StageName: "test-stage",
718+
Clusters: []placementv1beta1.ClusterUpdatingStatus{
719+
{
720+
ClusterName: "cluster-1",
721+
// No conditions - cluster has not started updating yet.
722+
},
723+
},
724+
},
725+
},
726+
UpdateStrategySnapshot: &placementv1beta1.UpdateStrategySpec{
727+
Stages: []placementv1beta1.StageConfig{
728+
{
729+
Name: "test-stage",
730+
MaxConcurrency: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
731+
},
732+
},
733+
},
734+
},
735+
},
736+
bindings: []placementv1beta1.BindingObj{
737+
&placementv1beta1.ClusterResourceBinding{
738+
ObjectMeta: metav1.ObjectMeta{
739+
Name: "binding-1",
740+
Generation: 1,
741+
},
742+
Spec: placementv1beta1.ResourceBindingSpec{
743+
TargetCluster: "cluster-1",
744+
ResourceSnapshotName: "test-placement-1-snapshot", // Already synced.
745+
State: placementv1beta1.BindingStateBound, // Already Bound.
746+
},
747+
Status: placementv1beta1.ResourceBindingStatus{
748+
Conditions: []metav1.Condition{
749+
{
750+
Type: string(placementv1beta1.ResourceBindingRolloutStarted),
751+
Status: metav1.ConditionTrue,
752+
ObservedGeneration: 1,
753+
Reason: condition.RolloutStartedReason,
754+
},
755+
{
756+
Type: string(placementv1beta1.ResourceBindingApplied),
757+
Status: metav1.ConditionFalse,
758+
ObservedGeneration: 1,
759+
Reason: condition.ApplyFailedReason,
760+
},
761+
},
762+
},
763+
},
764+
},
765+
interceptorFunc: nil,
766+
wantErr: errors.New("cluster updating encountered an error at stage"),
767+
expectWaitTime: 0,
768+
},
705769
}
706770

707771
for _, tt := range tests {

0 commit comments

Comments
 (0)