@@ -922,6 +922,71 @@ func TestServerResourcesRetry(t *testing.T) {
922922 }
923923}
924924
925+ func TestSync_getSyncTasks_FailureMessage (t * testing.T ) {
926+ syncCtx := newTestSyncCtx (nil )
927+ testSvc := testingutils .NewService ()
928+ testSvc .SetName ("test-service" )
929+ testSvc .SetNamespace (testingutils .FakeArgoCDNamespace )
930+
931+ // Mock discovery failure for this resource
932+ fakeDisco := & fakedisco.FakeDiscovery {
933+ Fake : & testcore.Fake {
934+ Resources : []* metav1.APIResourceList {},
935+ },
936+ }
937+ fakeDisco .Fake .PrependReactor ("get" , "resource" , func (action testcore.Action ) (handled bool , ret runtime.Object , err error ) {
938+ return true , nil , errors .New ("discovery failed" )
939+ })
940+ syncCtx .disco = fakeDisco
941+
942+ syncCtx .resources = groupResources (ReconciliationResult {
943+ Live : []* unstructured.Unstructured {testSvc },
944+ Target : []* unstructured.Unstructured {testSvc },
945+ })
946+
947+ syncCtx .Sync ()
948+ phase , msg , _ := syncCtx .GetState ()
949+
950+ assert .Equal (t , synccommon .OperationFailed , phase )
951+ assert .Contains (t , msg , "one or more synchronization tasks are not valid" )
952+ assert .Contains (t , msg , "discovery failed" )
953+ }
954+
955+ func Test_getSyncTasks_ErrorCaching (t * testing.T ) {
956+ syncCtx := newTestSyncCtx (nil )
957+
958+ // Create two services with the same GVK
959+ svc1 := testingutils .NewService ()
960+ svc1 .SetName ("svc1" )
961+ svc2 := testingutils .NewService ()
962+ svc2 .SetName ("svc2" )
963+
964+ // Mock discovery failure
965+ discoveryCalls := 0
966+ fakeDisco := & fakedisco.FakeDiscovery {
967+ Fake : & testcore.Fake {
968+ Resources : []* metav1.APIResourceList {},
969+ },
970+ }
971+ fakeDisco .Fake .PrependReactor ("get" , "resource" , func (action testcore.Action ) (handled bool , ret runtime.Object , err error ) {
972+ discoveryCalls ++
973+ return true , nil , errors .New ("persistent discovery error" )
974+ })
975+ syncCtx .disco = fakeDisco
976+
977+ syncCtx .resources = groupResources (ReconciliationResult {
978+ Live : []* unstructured.Unstructured {svc1 , svc2 },
979+ Target : []* unstructured.Unstructured {svc1 , svc2 },
980+ })
981+
982+ tasks , ok := syncCtx .getSyncTasks ()
983+ assert .False (t , ok )
984+ assert .NotNil (t , tasks )
985+
986+ // discoveryCalls should be 1 if caching works.
987+ assert .Equal (t , 1 , discoveryCalls , "Discovery should have been called only once due to caching" )
988+ }
989+
925990func TestDoNotSyncOrPruneHooks (t * testing.T ) {
926991 syncCtx := newTestSyncCtx (nil , WithOperationSettings (false , false , false , true ))
927992 targetPod := testingutils .NewPod ()
0 commit comments