@@ -734,6 +734,160 @@ func TestUpdateNudgedComponentStatus(t *testing.T) {
734734 }
735735}
736736
737+ func TestIsArgoCDManaged (t * testing.T ) {
738+ // reusable application for tests with no ArgoCD tracking
739+ normalApplication := & appstudiov1alpha1.Application {
740+ ObjectMeta : v1.ObjectMeta {
741+ Name : "application1" ,
742+ Namespace : "default" ,
743+ },
744+ }
745+
746+ t .Run ("should return true when component has ArgoCD annotation" , func (t * testing.T ) {
747+ component := & appstudiov1alpha1.Component {
748+ ObjectMeta : v1.ObjectMeta {
749+ Name : "component1" ,
750+ Namespace : "default" ,
751+ Annotations : map [string ]string {
752+ "argocd.argoproj.io/tracking-id" : "123" ,
753+ },
754+ },
755+ }
756+ result := isArgoCDManaged (component , normalApplication )
757+
758+ if ! result {
759+ t .Errorf ("TestIsArgoCDManaged(): should return true when component has ArgoCD annotation, got false" )
760+ }
761+ })
762+
763+ t .Run ("should return true when component has ArgoCD label" , func (t * testing.T ) {
764+ component := & appstudiov1alpha1.Component {
765+ ObjectMeta : v1.ObjectMeta {
766+ Name : "component1" ,
767+ Namespace : "default" ,
768+ Labels : map [string ]string {
769+ "argocd.argoproj.io/tracking-id" : "123" ,
770+ },
771+ },
772+ }
773+
774+ result := isArgoCDManaged (component , normalApplication )
775+
776+ if ! result {
777+ t .Errorf ("TestIsArgoCDManaged(): should return true when component has ArgoCD label, got false" )
778+ }
779+ })
780+
781+ t .Run ("should return true when application has ArgoCD annotation" , func (t * testing.T ) {
782+ // Component without ArgoCD tracking
783+ component := & appstudiov1alpha1.Component {
784+ ObjectMeta : v1.ObjectMeta {
785+ Name : "component1" ,
786+ Namespace : "default" ,
787+ // Component has no ArgoCD tracking - looks normal
788+ },
789+ }
790+
791+ // Application HAS ArgoCD annotation
792+ application := & appstudiov1alpha1.Application {
793+ ObjectMeta : v1.ObjectMeta {
794+ Name : "application1" ,
795+ Namespace : "default" ,
796+ Annotations : map [string ]string {
797+ "argocd.argoproj.io/tracking-id" : "123" ,
798+ },
799+ },
800+ }
801+
802+ result := isArgoCDManaged (component , application )
803+
804+ if ! result {
805+ t .Errorf ("TestIsArgoCDManaged(): should return true when application has ArgoCD annotation, got false" )
806+ }
807+ })
808+
809+ t .Run ("should return true when application has ArgoCD label" , func (t * testing.T ) {
810+ component := & appstudiov1alpha1.Component {
811+ ObjectMeta : v1.ObjectMeta {
812+ Name : "component1" ,
813+ Namespace : "default" ,
814+ // Component has no ArgoCD tracking
815+ },
816+ }
817+
818+ // Application HAS ArgoCD label (not annotation)
819+ application := & appstudiov1alpha1.Application {
820+ ObjectMeta : v1.ObjectMeta {
821+ Name : "application1" ,
822+ Namespace : "default" ,
823+ Labels : map [string ]string {
824+ "argocd.argoproj.io/tracking-id" : "123" ,
825+ },
826+ },
827+ }
828+
829+ result := isArgoCDManaged (component , application )
830+
831+ if ! result {
832+ t .Errorf ("TestIsArgoCDManaged(): should return true when application has ArgoCD label, got false" )
833+ }
834+ })
835+
836+ t .Run ("should return false when component and application both have no ArgoCD tracking" , func (t * testing.T ) {
837+ component := & appstudiov1alpha1.Component {
838+ ObjectMeta : v1.ObjectMeta {
839+ Name : "component1" ,
840+ Namespace : "default" ,
841+ // No annotations, no labels - completely normal component
842+ },
843+ }
844+
845+ result := isArgoCDManaged (component , normalApplication )
846+
847+ if result {
848+ t .Errorf ("TestIsArgoCDManaged(): should return false when neither has ArgoCD tracking, got true" )
849+ }
850+ })
851+
852+ t .Run ("should return false when component has no ArgoCD and application is nil" , func (t * testing.T ) {
853+ component := & appstudiov1alpha1.Component {
854+ ObjectMeta : v1.ObjectMeta {
855+ Name : "component1" ,
856+ Namespace : "default" ,
857+ // Component has no ArgoCD tracking
858+ },
859+ }
860+
861+ // Call with nil application - should not panic and should return false
862+ result := isArgoCDManaged (component , nil )
863+
864+ if result {
865+ t .Errorf ("TestIsArgoCDManaged(): should return false when component has no ArgoCD and application is nil, got true" )
866+ }
867+ })
868+
869+ t .Run ("should return true when component has ArgoCD annotation even with nil application" , func (t * testing.T ) {
870+ component := & appstudiov1alpha1.Component {
871+ ObjectMeta : v1.ObjectMeta {
872+ Name : "component1" ,
873+ Namespace : "default" ,
874+ // Component HAS ArgoCD annotation
875+ Annotations : map [string ]string {
876+ "argocd.argoproj.io/tracking-id" : "123" ,
877+ },
878+ },
879+ }
880+
881+ // Even with nil application, should return true because component has annotation
882+ result := isArgoCDManaged (component , nil )
883+
884+ if ! result {
885+ t .Errorf ("TestIsArgoCDManaged(): should return true when component has ArgoCD annotation even with nil application, got false" )
886+ }
887+ })
888+
889+ }
890+
737891// setUpComponentsForFakeErrorClient creates a fake controller-runtime Kube client with components to test error scenarios
738892func setUpComponentsForFakeErrorClient (t * testing.T ) * FakeClient {
739893 fakeErrorClient := NewFakeErrorClient (t )
0 commit comments