@@ -79,6 +79,65 @@ func Test_GetImagesFromApplication(t *testing.T) {
79
79
})
80
80
}
81
81
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
+
82
141
func Test_GetApplicationType (t * testing.T ) {
83
142
t .Run ("Get application of type Helm" , func (t * testing.T ) {
84
143
application := & v1alpha1.Application {
@@ -541,7 +600,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
541
600
fmt .Sprintf (common .HelmParamImageSpecAnnotation , "myimg" ): "image.blub" ,
542
601
fmt .Sprintf (common .HelmParamImageTagAnnotation , "myimg" ): "image.blab" ,
543
602
}
544
- name , tag := getHelmParamNamesFromAnnotation (annotations , "" )
603
+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
604
+ ImageAlias : "" ,
605
+ })
545
606
assert .Equal (t , "image.name" , name )
546
607
assert .Equal (t , "image.tag" , tag )
547
608
})
@@ -551,7 +612,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
551
612
fmt .Sprintf (common .HelmParamImageSpecAnnotation , "myimg" ): "image.path" ,
552
613
fmt .Sprintf (common .HelmParamImageTagAnnotation , "myimg" ): "image.tag" ,
553
614
}
554
- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
615
+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
616
+ ImageAlias : "myimg" ,
617
+ })
555
618
assert .Equal (t , "image.path" , name )
556
619
assert .Empty (t , tag )
557
620
})
@@ -561,7 +624,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
561
624
fmt .Sprintf (common .HelmParamImageNameAnnotation , "myimg" ): "image.name" ,
562
625
fmt .Sprintf (common .HelmParamImageTagAnnotation , "myimg" ): "image.tag" ,
563
626
}
564
- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
627
+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
628
+ ImageAlias : "myimg" ,
629
+ })
565
630
assert .Equal (t , "image.name" , name )
566
631
assert .Equal (t , "image.tag" , tag )
567
632
})
@@ -571,7 +636,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
571
636
fmt .Sprintf (common .HelmParamImageNameAnnotation , "otherimg" ): "image.name" ,
572
637
fmt .Sprintf (common .HelmParamImageTagAnnotation , "otherimg" ): "image.tag" ,
573
638
}
574
- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
639
+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
640
+ ImageAlias : "myimg" ,
641
+ })
575
642
assert .Empty (t , name )
576
643
assert .Empty (t , tag )
577
644
})
@@ -580,14 +647,18 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
580
647
annotations := map [string ]string {
581
648
fmt .Sprintf (common .HelmParamImageTagAnnotation , "myimg" ): "image.tag" ,
582
649
}
583
- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
650
+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
651
+ ImageAlias : "myimg" ,
652
+ })
584
653
assert .Empty (t , name )
585
654
assert .Equal (t , "image.tag" , tag )
586
655
})
587
656
588
657
t .Run ("No suitable annotations found" , func (t * testing.T ) {
589
658
annotations := map [string ]string {}
590
- name , tag := getHelmParamNamesFromAnnotation (annotations , "myimg" )
659
+ name , tag := getHelmParamNamesFromAnnotation (annotations , & image.ContainerImage {
660
+ ImageAlias : "myimg" ,
661
+ })
591
662
assert .Empty (t , name )
592
663
assert .Empty (t , tag )
593
664
})
0 commit comments