@@ -79,6 +79,65 @@ func Test_GetImagesFromApplication(t *testing.T) {
7979 })
8080}
8181
82+ func Test_GetImagesAndAliasesFromApplication (t * testing.T ) {
83+ t .Run ("Get list of images from application" , func (t * testing.T ) {
84+ application := & v1alpha1.Application {
85+ ObjectMeta : v1.ObjectMeta {
86+ Name : "test-app" ,
87+ Namespace : "argocd" ,
88+ },
89+ Spec : v1alpha1.ApplicationSpec {},
90+ Status : v1alpha1.ApplicationStatus {
91+ Summary : v1alpha1.ApplicationSummary {
92+ Images : []string {"nginx:1.12.2" , "that/image" , "quay.io/dexidp/dex:v1.23.0" },
93+ },
94+ },
95+ }
96+ imageList := GetImagesAndAliasesFromApplication (application )
97+ require .Len (t , imageList , 3 )
98+ assert .Equal (t , "nginx" , imageList [0 ].ImageName )
99+ assert .Equal (t , "that/image" , imageList [1 ].ImageName )
100+ assert .Equal (t , "dexidp/dex" , imageList [2 ].ImageName )
101+ })
102+
103+ t .Run ("Get list of images and image aliases from application that has no images" , func (t * testing.T ) {
104+ application := & v1alpha1.Application {
105+ ObjectMeta : v1.ObjectMeta {
106+ Name : "test-app" ,
107+ Namespace : "argocd" ,
108+ },
109+ Spec : v1alpha1.ApplicationSpec {},
110+ Status : v1alpha1.ApplicationStatus {
111+ Summary : v1alpha1.ApplicationSummary {},
112+ },
113+ }
114+ imageList := GetImagesAndAliasesFromApplication (application )
115+ assert .Empty (t , imageList )
116+ })
117+
118+ t .Run ("Get list of images and aliases from application annotations" , func (t * testing.T ) {
119+ application := & v1alpha1.Application {
120+ ObjectMeta : v1.ObjectMeta {
121+ Name : "test-app" ,
122+ Namespace : "argocd" ,
123+ Annotations : map [string ]string {
124+ common .ImageUpdaterAnnotation : "webserver=nginx" ,
125+ },
126+ },
127+ Spec : v1alpha1.ApplicationSpec {},
128+ Status : v1alpha1.ApplicationStatus {
129+ Summary : v1alpha1.ApplicationSummary {
130+ Images : []string {"nginx:1.12.2" },
131+ },
132+ },
133+ }
134+ imageList := GetImagesAndAliasesFromApplication (application )
135+ require .Len (t , imageList , 1 )
136+ assert .Equal (t , "nginx" , imageList [0 ].ImageName )
137+ assert .Equal (t , "webserver" , imageList [0 ].ImageAlias )
138+ })
139+ }
140+
82141func Test_GetApplicationType (t * testing.T ) {
83142 t .Run ("Get application of type Helm" , func (t * testing.T ) {
84143 application := & v1alpha1.Application {
@@ -541,7 +600,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
541600 fmt .Sprintf (common .HelmParamImageSpecAnnotation , "myimg" ): "image.blub" ,
542601 fmt .Sprintf (common .HelmParamImageTagAnnotation , "myimg" ): "image.blab" ,
543602 }
544- name , tag := getHelmParamNamesFromAnnotation (annotations , "" )
603+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
604+ ImageAlias : "" ,
605+ })
545606 assert .Equal (t , "image.name" , name )
546607 assert .Equal (t , "image.tag" , tag )
547608 })
@@ -551,7 +612,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
551612 fmt .Sprintf (common .HelmParamImageSpecAnnotation , "myimg" ): "image.path" ,
552613 fmt .Sprintf (common .HelmParamImageTagAnnotation , "myimg" ): "image.tag" ,
553614 }
554- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
615+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
616+ ImageAlias : "myimg" ,
617+ })
555618 assert .Equal (t , "image.path" , name )
556619 assert .Empty (t , tag )
557620 })
@@ -561,7 +624,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
561624 fmt .Sprintf (common .HelmParamImageNameAnnotation , "myimg" ): "image.name" ,
562625 fmt .Sprintf (common .HelmParamImageTagAnnotation , "myimg" ): "image.tag" ,
563626 }
564- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
627+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
628+ ImageAlias : "myimg" ,
629+ })
565630 assert .Equal (t , "image.name" , name )
566631 assert .Equal (t , "image.tag" , tag )
567632 })
@@ -571,7 +636,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
571636 fmt .Sprintf (common .HelmParamImageNameAnnotation , "otherimg" ): "image.name" ,
572637 fmt .Sprintf (common .HelmParamImageTagAnnotation , "otherimg" ): "image.tag" ,
573638 }
574- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
639+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
640+ ImageAlias : "myimg" ,
641+ })
575642 assert .Empty (t , name )
576643 assert .Empty (t , tag )
577644 })
@@ -580,14 +647,18 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
580647 annotations := map [string ]string {
581648 fmt .Sprintf (common .HelmParamImageTagAnnotation , "myimg" ): "image.tag" ,
582649 }
583- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
650+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
651+ ImageAlias : "myimg" ,
652+ })
584653 assert .Empty (t , name )
585654 assert .Equal (t , "image.tag" , tag )
586655 })
587656
588657 t .Run ("No suitable annotations found" , func (t * testing.T ) {
589658 annotations := map [string ]string {}
590- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
659+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
660+ ImageAlias : "myimg" ,
661+ })
591662 assert .Empty (t , name )
592663 assert .Empty (t , tag )
593664 })
0 commit comments