@@ -468,9 +468,9 @@ func Test_SetKustomizeImage(t *testing.T) {
468
468
img := image .NewFromIdentifier ("jannfis/foobar:1.0.1" )
469
469
err := SetKustomizeImage (app , img )
470
470
require .NoError (t , err )
471
- require .NotNil (t , app .Spec .Source .Kustomize )
472
- assert .Len (t , app .Spec .Source .Kustomize .Images , 1 )
473
- assert .Equal (t , v1alpha1 .KustomizeImage ("jannfis/foobar:1.0.1" ), app .Spec .Source .Kustomize .Images [0 ])
471
+ require .NotNil (t , app .Spec .GetSources ()[ 0 ] .Kustomize )
472
+ assert .Len (t , app .Spec .GetSources ()[ 0 ] .Kustomize .Images , 1 )
473
+ assert .Equal (t , v1alpha1 .KustomizeImage ("jannfis/foobar:1.0.1" ), app .Spec .GetSources ()[ 0 ] .Kustomize .Images [0 ])
474
474
})
475
475
476
476
t .Run ("Test set Kustomize image parameters on Kustomize app with no params set" , func (t * testing.T ) {
@@ -494,9 +494,9 @@ func Test_SetKustomizeImage(t *testing.T) {
494
494
img := image .NewFromIdentifier ("jannfis/foobar:1.0.1" )
495
495
err := SetKustomizeImage (app , img )
496
496
require .NoError (t , err )
497
- require .NotNil (t , app .Spec .Source .Kustomize )
498
- assert .Len (t , app .Spec .Source .Kustomize .Images , 1 )
499
- assert .Equal (t , v1alpha1 .KustomizeImage ("jannfis/foobar:1.0.1" ), app .Spec .Source .Kustomize .Images [0 ])
497
+ require .NotNil (t , app .Spec .GetSources ()[ 0 ] .Kustomize )
498
+ assert .Len (t , app .Spec .GetSources ()[ 0 ] .Kustomize .Images , 1 )
499
+ assert .Equal (t , v1alpha1 .KustomizeImage ("jannfis/foobar:1.0.1" ), app .Spec .GetSources ()[ 0 ] .Kustomize .Images [0 ])
500
500
})
501
501
502
502
t .Run ("Test set Kustomize image parameters on non-Kustomize app" , func (t * testing.T ) {
@@ -558,9 +558,9 @@ func Test_SetKustomizeImage(t *testing.T) {
558
558
img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
559
559
err := SetKustomizeImage (app , img )
560
560
require .NoError (t , err )
561
- require .NotNil (t , app .Spec .Source .Kustomize )
562
- assert .Len (t , app .Spec .Source .Kustomize .Images , 1 )
563
- assert .Equal (t , v1alpha1 .KustomizeImage ("foobar=jannfis/foobar:1.0.1" ), app .Spec .Source .Kustomize .Images [0 ])
561
+ require .NotNil (t , app .Spec .GetSources ()[ 0 ] .Kustomize )
562
+ assert .Len (t , app .Spec .GetSources ()[ 0 ] .Kustomize .Images , 1 )
563
+ assert .Equal (t , v1alpha1 .KustomizeImage ("foobar=jannfis/foobar:1.0.1" ), app .Spec .GetSources ()[ 0 ] .Kustomize .Images [0 ])
564
564
})
565
565
566
566
}
@@ -606,12 +606,12 @@ func Test_SetHelmImage(t *testing.T) {
606
606
607
607
err := SetHelmImage (app , img )
608
608
require .NoError (t , err )
609
- require .NotNil (t , app .Spec .Source .Helm )
610
- assert .Len (t , app .Spec .Source .Helm .Parameters , 2 )
609
+ require .NotNil (t , app .Spec .GetSources ()[ 0 ] .Helm )
610
+ assert .Len (t , app .Spec .GetSources ()[ 0 ] .Helm .Parameters , 2 )
611
611
612
612
// Find correct parameter
613
613
var tagParam v1alpha1.HelmParameter
614
- for _ , p := range app .Spec .Source .Helm .Parameters {
614
+ for _ , p := range app .Spec .GetSources ()[ 0 ] .Helm .Parameters {
615
615
if p .Name == "image.tag" {
616
616
tagParam = p
617
617
break
@@ -649,12 +649,67 @@ func Test_SetHelmImage(t *testing.T) {
649
649
650
650
err := SetHelmImage (app , img )
651
651
require .NoError (t , err )
652
- require .NotNil (t , app .Spec .Source .Helm )
653
- assert .Len (t , app .Spec .Source .Helm .Parameters , 2 )
652
+ require .NotNil (t , app .Spec .GetSources ()[ 0 ] .Helm )
653
+ assert .Len (t , app .Spec .GetSources ()[ 0 ] .Helm .Parameters , 2 )
654
654
655
655
// Find correct parameter
656
656
var tagParam v1alpha1.HelmParameter
657
- for _ , p := range app .Spec .Source .Helm .Parameters {
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 )
707
+ require .NotNil (t , app .Spec .GetSources ()[0 ].Helm )
708
+ assert .Len (t , app .Spec .GetSources ()[0 ].Helm .Parameters , 2 )
709
+
710
+ // Find correct parameter
711
+ var tagParam v1alpha1.HelmParameter
712
+ for _ , p := range app .Spec .GetSources ()[0 ].Helm .Parameters {
658
713
if p .Name == "image.tag" {
659
714
tagParam = p
660
715
break
@@ -703,12 +758,12 @@ func Test_SetHelmImage(t *testing.T) {
703
758
704
759
err := SetHelmImage (app , img )
705
760
require .NoError (t , err )
706
- require .NotNil (t , app .Spec .Source .Helm )
707
- assert .Len (t , app .Spec .Source .Helm .Parameters , 4 )
761
+ require .NotNil (t , app .Spec .GetSources ()[ 0 ] .Helm )
762
+ assert .Len (t , app .Spec .GetSources ()[ 0 ] .Helm .Parameters , 4 )
708
763
709
764
// Find correct parameter
710
765
var tagParam v1alpha1.HelmParameter
711
- for _ , p := range app .Spec .Source .Helm .Parameters {
766
+ for _ , p := range app .Spec .GetSources ()[ 0 ] .Helm .Parameters {
712
767
if p .Name == "foobar.image.tag" {
713
768
tagParam = p
714
769
break
@@ -818,7 +873,7 @@ func TestKubernetesClient_UpdateSpec_Conflict(t *testing.T) {
818
873
819
874
require .NoError (t , err )
820
875
821
- assert .Equal (t , "https://github.com/argoproj/argocd-example-apps" , spec .Source .RepoURL )
876
+ assert .Equal (t , "https://github.com/argoproj/argocd-example-apps" , spec .GetSources ()[ 0 ] .RepoURL )
822
877
}
823
878
824
879
func Test_parseImageList (t * testing.T ) {
0 commit comments