@@ -79,7 +79,7 @@ func Test_GetImagesFromApplication(t *testing.T) {
79
79
})
80
80
}
81
81
82
- func Test_GetApplicationType (t * testing.T ) {
82
+ func Test_GetApplicationTypeForSource (t * testing.T ) {
83
83
t .Run ("Get application of type Helm" , func (t * testing.T ) {
84
84
application := & v1alpha1.Application {
85
85
ObjectMeta : v1.ObjectMeta {
@@ -94,7 +94,7 @@ func Test_GetApplicationType(t *testing.T) {
94
94
},
95
95
},
96
96
}
97
- appType := GetApplicationType (application )
97
+ appType := GetApplicationTypeForSource (application , 0 )
98
98
assert .Equal (t , ApplicationTypeHelm , appType )
99
99
assert .Equal (t , "Helm" , appType .String ())
100
100
})
@@ -113,7 +113,7 @@ func Test_GetApplicationType(t *testing.T) {
113
113
},
114
114
},
115
115
}
116
- appType := GetApplicationType (application )
116
+ appType := GetApplicationTypeForSource (application , 0 )
117
117
assert .Equal (t , ApplicationTypeKustomize , appType )
118
118
assert .Equal (t , "Kustomize" , appType .String ())
119
119
})
@@ -132,7 +132,7 @@ func Test_GetApplicationType(t *testing.T) {
132
132
},
133
133
},
134
134
}
135
- appType := GetApplicationType (application )
135
+ appType := GetApplicationTypeForSource (application , 0 )
136
136
assert .Equal (t , ApplicationTypeUnsupported , appType )
137
137
assert .Equal (t , "Unsupported" , appType .String ())
138
138
})
@@ -154,7 +154,7 @@ func Test_GetApplicationType(t *testing.T) {
154
154
},
155
155
},
156
156
}
157
- appType := GetApplicationType (application )
157
+ appType := GetApplicationTypeForSource (application , 0 )
158
158
assert .Equal (t , ApplicationTypeKustomize , appType )
159
159
})
160
160
@@ -466,8 +466,8 @@ func Test_SetKustomizeImage(t *testing.T) {
466
466
},
467
467
}
468
468
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 )
471
471
require .NotNil (t , app .Spec .GetSources ()[0 ].Kustomize )
472
472
assert .Len (t , app .Spec .GetSources ()[0 ].Kustomize .Images , 1 )
473
473
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) {
492
492
},
493
493
}
494
494
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 )
497
497
require .NotNil (t , app .Spec .GetSources ()[0 ].Kustomize )
498
498
assert .Len (t , app .Spec .GetSources ()[0 ].Kustomize .Images , 1 )
499
499
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) {
524
524
},
525
525
}
526
526
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 )
529
529
})
530
530
531
531
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) {
556
556
},
557
557
}
558
558
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 )
561
561
require .NotNil (t , app .Spec .GetSources ()[0 ].Kustomize )
562
562
assert .Len (t , app .Spec .GetSources ()[0 ].Kustomize .Images , 1 )
563
563
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) {
604
604
605
605
img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
606
606
607
- err := SetHelmImage (app , img )
608
- require . NoError (t , err )
607
+ updated := SetHelmImageWithIndex (app , 0 , img )
608
+ assert . True (t , updated )
609
609
require .NotNil (t , app .Spec .GetSources ()[0 ].Helm )
610
610
assert .Len (t , app .Spec .GetSources ()[0 ].Helm .Parameters , 2 )
611
611
@@ -647,63 +647,8 @@ func Test_SetHelmImage(t *testing.T) {
647
647
648
648
img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
649
649
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 )
707
652
require .NotNil (t , app .Spec .GetSources ()[0 ].Helm )
708
653
assert .Len (t , app .Spec .GetSources ()[0 ].Helm .Parameters , 2 )
709
654
@@ -756,8 +701,8 @@ func Test_SetHelmImage(t *testing.T) {
756
701
757
702
img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
758
703
759
- err := SetHelmImage (app , img )
760
- require . NoError (t , err )
704
+ updated := SetHelmImageWithIndex (app , 0 , img )
705
+ assert . True (t , updated )
761
706
require .NotNil (t , app .Spec .GetSources ()[0 ].Helm )
762
707
assert .Len (t , app .Spec .GetSources ()[0 ].Helm .Parameters , 4 )
763
708
@@ -797,8 +742,8 @@ func Test_SetHelmImage(t *testing.T) {
797
742
798
743
img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
799
744
800
- err := SetHelmImage (app , img )
801
- require . Error (t , err )
745
+ updated := SetHelmImageWithIndex (app , 0 , img )
746
+ assert . False (t , updated )
802
747
})
803
748
804
749
}
0 commit comments