@@ -26,6 +26,7 @@ import (
26
26
"github.com/stretchr/testify/assert"
27
27
corev1 "k8s.io/api/core/v1"
28
28
rbacv1 "k8s.io/api/rbac/v1"
29
+ apierrors "k8s.io/apimachinery/pkg/api/errors"
29
30
"k8s.io/apimachinery/pkg/api/meta"
30
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
32
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -579,6 +580,7 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
579
580
expectedError bool
580
581
wrongWorkNS bool
581
582
workApplyFunc func (work * workv1alpha1.Work )
583
+ assertFunc func (t * testing.T , dynamicClientSets * dynamicfake.FakeDynamicClient )
582
584
}{
583
585
{
584
586
name : "failed to exec NeedUpdate" ,
@@ -669,6 +671,23 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
669
671
work .SetDeletionTimestamp (ptr .To (metav1 .Now ()))
670
672
},
671
673
},
674
+ {
675
+ name : "resource not found, work suspendDispatching true, should not recreate resource" ,
676
+ obj : newPodObj ("karmada-es-cluster" ),
677
+ pod : nil , // Simulate the resource does not exist in the member cluster
678
+ raw : []byte (`{"apiVersion":"v1","kind":"Pod","metadata":{"name":"pod","namespace":"default"}}` ),
679
+ controllerWithoutInformer : true ,
680
+ expectedError : false ,
681
+ workApplyFunc : func (work * workv1alpha1.Work ) {
682
+ work .Spec .SuspendDispatching = ptr .To (true )
683
+ },
684
+ assertFunc : func (t * testing.T , dynamicClientSets * dynamicfake.FakeDynamicClient ) {
685
+ gvr := corev1 .SchemeGroupVersion .WithResource ("pods" )
686
+ obj , err := dynamicClientSets .Resource (gvr ).Namespace ("default" ).Get (context .Background (), "pod" , metav1.GetOptions {})
687
+ assert .True (t , apierrors .IsNotFound (err ), "expected a NotFound error but got: %s" , err )
688
+ assert .Nil (t , obj )
689
+ },
690
+ },
672
691
}
673
692
674
693
for _ , tt := range tests {
@@ -709,6 +728,10 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
709
728
} else {
710
729
assert .NoError (t , err )
711
730
}
731
+
732
+ if tt .assertFunc != nil {
733
+ tt .assertFunc (t , dynamicClientSet )
734
+ }
712
735
})
713
736
}
714
737
}
0 commit comments