@@ -1005,6 +1005,89 @@ func Test_SetHelmImage(t *testing.T) {
10051005 require .Error (t , err )
10061006 })
10071007
1008+ t .Run ("Test set Helm image parameters when two paths are provided" , func (t * testing.T ) {
1009+ app := & v1alpha1.Application {
1010+ ObjectMeta : v1.ObjectMeta {
1011+ Name : "test-app" ,
1012+ Namespace : "testns" ,
1013+ Annotations : map [string ]string {
1014+ fmt .Sprintf (common .HelmParamImageNameAnnotation , "foobar" ): "foobar.image.name,foobar2.image.name" ,
1015+ fmt .Sprintf (common .HelmParamImageTagAnnotation , "foobar" ): "foobar.image.tag, foobar2.image.tag" ,
1016+ },
1017+ },
1018+ Spec : v1alpha1.ApplicationSpec {
1019+ Source : & v1alpha1.ApplicationSource {
1020+ Helm : & v1alpha1.ApplicationSourceHelm {
1021+ Parameters : []v1alpha1.HelmParameter {
1022+ {
1023+ Name : "image.tag" ,
1024+ Value : "1.0.0" ,
1025+ },
1026+ {
1027+ Name : "image.name" ,
1028+ Value : "jannfis/dummy" ,
1029+ },
1030+ },
1031+ },
1032+ },
1033+ },
1034+ Status : v1alpha1.ApplicationStatus {
1035+ SourceType : v1alpha1 .ApplicationSourceTypeHelm ,
1036+ Summary : v1alpha1.ApplicationSummary {
1037+ Images : []string {
1038+ "jannfis/foobar:1.0.0" ,
1039+ },
1040+ },
1041+ },
1042+ }
1043+
1044+ img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
1045+
1046+ err := SetHelmImage (app , img )
1047+ require .NoError (t , err )
1048+ require .NotNil (t , app .Spec .Source .Helm )
1049+ assert .Len (t , app .Spec .Source .Helm .Parameters , 6 )
1050+
1051+ // Find first correct parameter
1052+ var tagParam v1alpha1.HelmParameter
1053+ for _ , p := range app .Spec .Source .Helm .Parameters {
1054+ if p .Name == "foobar.image.tag" {
1055+ tagParam = p
1056+ break
1057+ }
1058+ }
1059+ assert .Equal (t , "1.0.1" , tagParam .Value )
1060+
1061+ // Find second correct parameter
1062+ var tagParamTwo v1alpha1.HelmParameter
1063+ for _ , p := range app .Spec .Source .Helm .Parameters {
1064+ if p .Name == "foobar.image.tag" {
1065+ tagParamTwo = p
1066+ break
1067+ }
1068+ }
1069+ assert .Equal (t , "1.0.1" , tagParamTwo .Value )
1070+
1071+ // Find first correct parameter
1072+ var nameParam v1alpha1.HelmParameter
1073+ for _ , p := range app .Spec .Source .Helm .Parameters {
1074+ if p .Name == "foobar.image.name" {
1075+ nameParam = p
1076+ break
1077+ }
1078+ }
1079+ assert .Equal (t , "jannfis/foobar" , nameParam .Value )
1080+
1081+ // Find second correct parameter
1082+ var nameParamTwo v1alpha1.HelmParameter
1083+ for _ , p := range app .Spec .Source .Helm .Parameters {
1084+ if p .Name == "foobar2.image.name" {
1085+ nameParamTwo = p
1086+ break
1087+ }
1088+ }
1089+ assert .Equal (t , "jannfis/foobar" , nameParamTwo .Value )
1090+ })
10081091}
10091092
10101093func TestKubernetesClient (t * testing.T ) {
0 commit comments