@@ -30,6 +30,68 @@ import (
3030)
3131
3232func Test_UpdateApplication (t * testing.T ) {
33+ t .Run ("Test kustomize w/ multiple images w/ different registry w/ different tags" , func (t * testing.T ) {
34+ mockClientFn := func (endpoint * registry.RegistryEndpoint , username , password string ) (registry.RegistryClient , error ) {
35+ regMock := regmock.RegistryClient {}
36+ regMock .On ("NewRepository" , mock .Anything ).Return (nil )
37+ regMock .On ("Tags" , mock .Anything ).Return ([]string {"1.0.2" , "1.0.3" }, nil )
38+ return & regMock , nil
39+ }
40+
41+ argoClient := argomock.ArgoCD {}
42+ argoClient .On ("UpdateSpec" , mock .Anything , mock .Anything ).Return (nil , nil )
43+
44+ kubeClient := kube.KubernetesClient {
45+ Clientset : fake .NewFakeKubeClient (),
46+ }
47+ annotations := map [string ]string {
48+ common .ImageUpdaterAnnotation : "foobar=gcr.io/jannfis/foobar:>=1.0.1,foobar=gcr.io/jannfis/barbar:>=1.0.1" ,
49+ }
50+ appImages := & ApplicationImages {
51+ Application : v1alpha1.Application {
52+ ObjectMeta : v1.ObjectMeta {
53+ Name : "guestbook" ,
54+ Namespace : "guestbook" ,
55+ Annotations : annotations ,
56+ },
57+ Spec : v1alpha1.ApplicationSpec {
58+ Source : v1alpha1.ApplicationSource {
59+ Kustomize : & v1alpha1.ApplicationSourceKustomize {
60+ Images : v1alpha1.KustomizeImages {
61+ "jannfis/foobar:1.0.1" ,
62+ "jannfis/barbar:1.0.1" ,
63+ },
64+ },
65+ },
66+ },
67+ Status : v1alpha1.ApplicationStatus {
68+ SourceType : v1alpha1 .ApplicationSourceTypeKustomize ,
69+ Summary : v1alpha1.ApplicationSummary {
70+ Images : []string {
71+ "gcr.io/jannfis/foobar:1.0.1" ,
72+ "gcr.io/jannfis/barbar:1.0.1" ,
73+ },
74+ },
75+ },
76+ },
77+ Images : * parseImageList (annotations ),
78+ }
79+ res := UpdateApplication (& UpdateConfiguration {
80+ NewRegFN : mockClientFn ,
81+ ArgoClient : & argoClient ,
82+ KubeClient : & kubeClient ,
83+ UpdateApp : appImages ,
84+ DryRun : false ,
85+ }, NewSyncIterationState ())
86+ assert .Equal (t , v1alpha1 .KustomizeImage ("gcr.io/jannfis/foobar:1.0.3" ), appImages .Application .Spec .Source .Kustomize .Images [0 ])
87+ assert .Equal (t , v1alpha1 .KustomizeImage ("gcr.io/jannfis/barbar:1.0.3" ), appImages .Application .Spec .Source .Kustomize .Images [1 ])
88+ assert .Equal (t , 0 , res .NumErrors )
89+ assert .Equal (t , 0 , res .NumSkipped )
90+ assert .Equal (t , 1 , res .NumApplicationsProcessed )
91+ assert .Equal (t , 2 , res .NumImagesConsidered )
92+ assert .Equal (t , 1 , res .NumImagesUpdated )
93+ })
94+
3395 t .Run ("Test successful update" , func (t * testing.T ) {
3496 mockClientFn := func (endpoint * registry.RegistryEndpoint , username , password string ) (registry.RegistryClient , error ) {
3597 regMock := regmock.RegistryClient {}
0 commit comments