@@ -79,7 +79,7 @@ func Test_GetImagesFromApplication(t *testing.T) {
7979 })
8080}
8181
82- func Test_GetApplicationType (t * testing.T ) {
82+ func Test_GetApplicationTypeForSource (t * testing.T ) {
8383 t .Run ("Get application of type Helm" , func (t * testing.T ) {
8484 application := & v1alpha1.Application {
8585 ObjectMeta : v1.ObjectMeta {
@@ -94,7 +94,7 @@ func Test_GetApplicationType(t *testing.T) {
9494 },
9595 },
9696 }
97- appType := GetApplicationType (application )
97+ appType := GetApplicationTypeForSource (application , 0 )
9898 assert .Equal (t , ApplicationTypeHelm , appType )
9999 assert .Equal (t , "Helm" , appType .String ())
100100 })
@@ -113,7 +113,7 @@ func Test_GetApplicationType(t *testing.T) {
113113 },
114114 },
115115 }
116- appType := GetApplicationType (application )
116+ appType := GetApplicationTypeForSource (application , 0 )
117117 assert .Equal (t , ApplicationTypeKustomize , appType )
118118 assert .Equal (t , "Kustomize" , appType .String ())
119119 })
@@ -132,7 +132,7 @@ func Test_GetApplicationType(t *testing.T) {
132132 },
133133 },
134134 }
135- appType := GetApplicationType (application )
135+ appType := GetApplicationTypeForSource (application , 0 )
136136 assert .Equal (t , ApplicationTypeUnsupported , appType )
137137 assert .Equal (t , "Unsupported" , appType .String ())
138138 })
@@ -154,7 +154,7 @@ func Test_GetApplicationType(t *testing.T) {
154154 },
155155 },
156156 }
157- appType := GetApplicationType (application )
157+ appType := GetApplicationTypeForSource (application , 0 )
158158 assert .Equal (t , ApplicationTypeKustomize , appType )
159159 })
160160
@@ -466,8 +466,8 @@ func Test_SetKustomizeImage(t *testing.T) {
466466 },
467467 }
468468 img := image .NewFromIdentifier ("jannfis/foobar:1.0.1" )
469- err := SetKustomizeImage (app , img )
470- require . NoError (t , err )
469+ updated := SetKustomizeImageWithIndex (app , 0 , img )
470+ assert . True (t , updated )
471471 require .NotNil (t , app .Spec .GetSources ()[0 ].Kustomize )
472472 assert .Len (t , app .Spec .GetSources ()[0 ].Kustomize .Images , 1 )
473473 assert .Equal (t , v1alpha1 .KustomizeImage ("jannfis/foobar:1.0.1" ), app .Spec .GetSources ()[0 ].Kustomize .Images [0 ])
@@ -492,8 +492,8 @@ func Test_SetKustomizeImage(t *testing.T) {
492492 },
493493 }
494494 img := image .NewFromIdentifier ("jannfis/foobar:1.0.1" )
495- err := SetKustomizeImage (app , img )
496- require . NoError (t , err )
495+ updated := SetKustomizeImageWithIndex (app , 0 , img )
496+ assert . True (t , updated )
497497 require .NotNil (t , app .Spec .GetSources ()[0 ].Kustomize )
498498 assert .Len (t , app .Spec .GetSources ()[0 ].Kustomize .Images , 1 )
499499 assert .Equal (t , v1alpha1 .KustomizeImage ("jannfis/foobar:1.0.1" ), app .Spec .GetSources ()[0 ].Kustomize .Images [0 ])
@@ -524,8 +524,8 @@ func Test_SetKustomizeImage(t *testing.T) {
524524 },
525525 }
526526 img := image .NewFromIdentifier ("jannfis/foobar:1.0.1" )
527- err := SetKustomizeImage (app , img )
528- require . Error (t , err )
527+ updated := SetKustomizeImageWithIndex (app , 0 , img )
528+ assert . False (t , updated )
529529 })
530530
531531 t .Run ("Test set Kustomize image parameters with alias name on Kustomize app with param already set" , func (t * testing.T ) {
@@ -556,8 +556,8 @@ func Test_SetKustomizeImage(t *testing.T) {
556556 },
557557 }
558558 img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
559- err := SetKustomizeImage (app , img )
560- require . NoError (t , err )
559+ updated := SetKustomizeImageWithIndex (app , 0 , img )
560+ assert . True (t , updated )
561561 require .NotNil (t , app .Spec .GetSources ()[0 ].Kustomize )
562562 assert .Len (t , app .Spec .GetSources ()[0 ].Kustomize .Images , 1 )
563563 assert .Equal (t , v1alpha1 .KustomizeImage ("foobar=jannfis/foobar:1.0.1" ), app .Spec .GetSources ()[0 ].Kustomize .Images [0 ])
@@ -604,8 +604,8 @@ func Test_SetHelmImage(t *testing.T) {
604604
605605 img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
606606
607- err := SetHelmImage (app , img )
608- require . NoError (t , err )
607+ updated := SetHelmImageWithIndex (app , 0 , img )
608+ assert . True (t , updated )
609609 require .NotNil (t , app .Spec .GetSources ()[0 ].Helm )
610610 assert .Len (t , app .Spec .GetSources ()[0 ].Helm .Parameters , 2 )
611611
@@ -647,63 +647,8 @@ func Test_SetHelmImage(t *testing.T) {
647647
648648 img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
649649
650- err := SetHelmImage (app , img )
651- require .NoError (t , err )
652- require .NotNil (t , app .Spec .GetSources ()[0 ].Helm )
653- assert .Len (t , app .Spec .GetSources ()[0 ].Helm .Parameters , 2 )
654-
655- // Find correct parameter
656- var tagParam v1alpha1.HelmParameter
657- for _ , p := range app .Spec .GetSources ()[0 ].Helm .Parameters {
658- if p .Name == "image.tag" {
659- tagParam = p
660- break
661- }
662- }
663- assert .Equal (t , "1.0.1" , tagParam .Value )
664- })
665-
666- t .Run ("Test set Helm image parameters on Helm app with multiple sources but existing parameters" , func (t * testing.T ) {
667- app := & v1alpha1.Application {
668- ObjectMeta : v1.ObjectMeta {
669- Name : "test-app" ,
670- Namespace : "testns" ,
671- Annotations : map [string ]string {
672- fmt .Sprintf (common .HelmParamImageNameAnnotation , "foobar" ): "image.name" ,
673- fmt .Sprintf (common .HelmParamImageTagAnnotation , "foobar" ): "image.tag" ,
674- fmt .Sprintf (common .HelmParamImageNameAnnotation , "baz" ): "image.name" ,
675- fmt .Sprintf (common .HelmParamImageTagAnnotation , "baz" ): "image.tag" ,
676- },
677- },
678- Spec : v1alpha1.ApplicationSpec {
679- Sources : v1alpha1.ApplicationSources {
680- v1alpha1.ApplicationSource {
681- Helm : & v1alpha1.ApplicationSourceHelm {},
682- },
683- v1alpha1.ApplicationSource {
684- Helm : & v1alpha1.ApplicationSourceHelm {},
685- },
686- },
687- },
688- Status : v1alpha1.ApplicationStatus {
689- SourceTypes : []v1alpha1.ApplicationSourceType {
690- v1alpha1 .ApplicationSourceTypeHelm ,
691- v1alpha1 .ApplicationSourceTypeHelm ,
692- },
693- SourceType : v1alpha1 .ApplicationSourceTypeHelm ,
694- Summary : v1alpha1.ApplicationSummary {
695- Images : []string {
696- "jannfis/foobar:1.0.0" ,
697- "cjm/baz:2.0.0" ,
698- },
699- },
700- },
701- }
702-
703- img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
704-
705- err := SetHelmImage (app , img )
706- require .NoError (t , err )
650+ updated := SetHelmImageWithIndex (app , 0 , img )
651+ assert .True (t , updated )
707652 require .NotNil (t , app .Spec .GetSources ()[0 ].Helm )
708653 assert .Len (t , app .Spec .GetSources ()[0 ].Helm .Parameters , 2 )
709654
@@ -756,8 +701,8 @@ func Test_SetHelmImage(t *testing.T) {
756701
757702 img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
758703
759- err := SetHelmImage (app , img )
760- require . NoError (t , err )
704+ updated := SetHelmImageWithIndex (app , 0 , img )
705+ assert . True (t , updated )
761706 require .NotNil (t , app .Spec .GetSources ()[0 ].Helm )
762707 assert .Len (t , app .Spec .GetSources ()[0 ].Helm .Parameters , 4 )
763708
@@ -797,8 +742,8 @@ func Test_SetHelmImage(t *testing.T) {
797742
798743 img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
799744
800- err := SetHelmImage (app , img )
801- require . Error (t , err )
745+ updated := SetHelmImageWithIndex (app , 0 , img )
746+ assert . False (t , updated )
802747 })
803748
804749}
0 commit comments