@@ -33,7 +33,9 @@ func Test_UpdateApplication(t *testing.T) {
3333 t .Run ("Test successful update" , func (t * testing.T ) {
3434 mockClientFn := func (endpoint * registry.RegistryEndpoint , username , password string ) (registry.RegistryClient , error ) {
3535 regMock := regmock.RegistryClient {}
36- regMock .On ("Tags" , mock .Anything ).Return ([]string {"1.0.1" }, nil )
36+ regMock .On ("Tags" , mock .MatchedBy (func (s string ) bool {
37+ return s == "jannfis/foobar"
38+ })).Return ([]string {"1.0.1" }, nil )
3739 return & regMock , nil
3840 }
3941
@@ -85,6 +87,130 @@ func Test_UpdateApplication(t *testing.T) {
8587 assert .Equal (t , 1 , res .NumImagesUpdated )
8688 })
8789
90+ t .Run ("Test kustomize w/ different registry" , func (t * testing.T ) {
91+ mockClientFn := func (endpoint * registry.RegistryEndpoint , username , password string ) (registry.RegistryClient , error ) {
92+ regMock := regmock.RegistryClient {}
93+ assert .Equal (t , endpoint .RegistryPrefix , "quay.io" )
94+ regMock .On ("Tags" , mock .Anything ).Return ([]string {"1.0.1" }, nil )
95+ return & regMock , nil
96+ }
97+
98+ argoClient := argomock.ArgoCD {}
99+ argoClient .On ("UpdateSpec" , mock .Anything , mock .Anything ).Return (nil , nil )
100+
101+ kubeClient := kube.KubernetesClient {
102+ Clientset : fake .NewFakeKubeClient (),
103+ }
104+ appImages := & ApplicationImages {
105+ Application : v1alpha1.Application {
106+ ObjectMeta : v1.ObjectMeta {
107+ Name : "guestbook" ,
108+ Namespace : "guestbook" ,
109+ Annotations : map [string ]string {
110+ "argocd-image-updater.argoproj.io/image-list" : "foobar=quay.io/jannfis/foobar:~1.0.0" ,
111+ "argocd-image-updater.argoproj.io/foobar.kustomize.image-name" : "jannfis/foobar" ,
112+ "argocd-image-updater.argoproj.io/foobar.force-update" : "true" ,
113+ },
114+ },
115+ Spec : v1alpha1.ApplicationSpec {
116+ Source : v1alpha1.ApplicationSource {
117+ Kustomize : & v1alpha1.ApplicationSourceKustomize {
118+ Images : v1alpha1.KustomizeImages {
119+ "jannfis/foobar:1.0.0" ,
120+ },
121+ },
122+ },
123+ },
124+ Status : v1alpha1.ApplicationStatus {
125+ SourceType : v1alpha1 .ApplicationSourceTypeKustomize ,
126+ Summary : v1alpha1.ApplicationSummary {
127+ Images : []string {
128+ "jannfis/foobar:1.0.0" ,
129+ },
130+ },
131+ },
132+ },
133+ Images : image.ContainerImageList {
134+ image .NewFromIdentifier ("quay.io/jannfis/foobar" ),
135+ },
136+ }
137+ res := UpdateApplication (& UpdateConfiguration {
138+ NewRegFN : mockClientFn ,
139+ ArgoClient : & argoClient ,
140+ KubeClient : & kubeClient ,
141+ UpdateApp : appImages ,
142+ DryRun : false ,
143+ }, NewSyncIterationState ())
144+ assert .Equal (t , 0 , res .NumErrors )
145+ assert .Equal (t , 0 , res .NumSkipped )
146+ assert .Equal (t , 1 , res .NumApplicationsProcessed )
147+ assert .Equal (t , 1 , res .NumImagesConsidered )
148+ assert .Equal (t , 1 , res .NumImagesUpdated )
149+ })
150+
151+ t .Run ("Test kustomize w/ different registry and org" , func (t * testing.T ) {
152+ mockClientFn := func (endpoint * registry.RegistryEndpoint , username , password string ) (registry.RegistryClient , error ) {
153+ regMock := regmock.RegistryClient {}
154+ assert .Equal (t , endpoint .RegistryPrefix , "quay.io" )
155+ regMock .On ("Tags" , mock .MatchedBy (func (s string ) bool {
156+ return s == "someorg/foobar"
157+ })).Return ([]string {"1.0.1" }, nil )
158+ return & regMock , nil
159+ }
160+
161+ argoClient := argomock.ArgoCD {}
162+ argoClient .On ("UpdateSpec" , mock .Anything , mock .Anything ).Return (nil , nil )
163+
164+ kubeClient := kube.KubernetesClient {
165+ Clientset : fake .NewFakeKubeClient (),
166+ }
167+ appImages := & ApplicationImages {
168+ Application : v1alpha1.Application {
169+ ObjectMeta : v1.ObjectMeta {
170+ Name : "guestbook" ,
171+ Namespace : "guestbook" ,
172+ Annotations : map [string ]string {
173+ "argocd-image-updater.argoproj.io/image-list" : "foobar=quay.io/someorg/foobar:~1.0.0" ,
174+ "argocd-image-updater.argoproj.io/foobar.kustomize.image-name" : "jannfis/foobar" ,
175+ "argocd-image-updater.argoproj.io/foobar.force-update" : "true" ,
176+ },
177+ },
178+ Spec : v1alpha1.ApplicationSpec {
179+ Source : v1alpha1.ApplicationSource {
180+ Kustomize : & v1alpha1.ApplicationSourceKustomize {
181+ Images : v1alpha1.KustomizeImages {
182+ "jannfis/foobar:1.0.0" ,
183+ },
184+ },
185+ },
186+ },
187+ Status : v1alpha1.ApplicationStatus {
188+ SourceType : v1alpha1 .ApplicationSourceTypeKustomize ,
189+ Summary : v1alpha1.ApplicationSummary {
190+ Images : []string {
191+ "jannfis/foobar:1.0.0" ,
192+ },
193+ },
194+ },
195+ },
196+ Images : image.ContainerImageList {
197+ image .NewFromIdentifier ("quay.io/someorg/foobar" ),
198+ },
199+ }
200+ res := UpdateApplication (& UpdateConfiguration {
201+ NewRegFN : mockClientFn ,
202+ ArgoClient : & argoClient ,
203+ KubeClient : & kubeClient ,
204+ UpdateApp : appImages ,
205+ DryRun : false ,
206+ }, NewSyncIterationState ())
207+ assert .Equal (t , 0 , res .NumErrors )
208+ assert .Equal (t , 0 , res .NumSkipped )
209+ assert .Equal (t , 1 , res .NumApplicationsProcessed )
210+ assert .Equal (t , 1 , res .NumImagesConsidered )
211+ assert .Equal (t , 1 , res .NumImagesUpdated )
212+ })
213+
88214 t .Run ("Test successful update when no tag is set in running workload" , func (t * testing.T ) {
89215 mockClientFn := func (endpoint * registry.RegistryEndpoint , username , password string ) (registry.RegistryClient , error ) {
90216 regMock := regmock.RegistryClient {}
0 commit comments