@@ -1046,6 +1046,89 @@ func Test_SetHelmImage(t *testing.T) {
10461046 require .Error (t , err )
10471047 })
10481048
1049+ t .Run ("Test set Helm image parameters when two paths are provided" , func (t * testing.T ) {
1050+ app := & v1alpha1.Application {
1051+ ObjectMeta : v1.ObjectMeta {
1052+ Name : "test-app" ,
1053+ Namespace : "testns" ,
1054+ Annotations : map [string ]string {
1055+ fmt .Sprintf (common .HelmParamImageNameAnnotation , "foobar" ): "foobar.image.name,foobar2.image.name" ,
1056+ fmt .Sprintf (common .HelmParamImageTagAnnotation , "foobar" ): "foobar.image.tag, foobar2.image.tag" ,
1057+ },
1058+ },
1059+ Spec : v1alpha1.ApplicationSpec {
1060+ Source : & v1alpha1.ApplicationSource {
1061+ Helm : & v1alpha1.ApplicationSourceHelm {
1062+ Parameters : []v1alpha1.HelmParameter {
1063+ {
1064+ Name : "image.tag" ,
1065+ Value : "1.0.0" ,
1066+ },
1067+ {
1068+ Name : "image.name" ,
1069+ Value : "jannfis/dummy" ,
1070+ },
1071+ },
1072+ },
1073+ },
1074+ },
1075+ Status : v1alpha1.ApplicationStatus {
1076+ SourceType : v1alpha1 .ApplicationSourceTypeHelm ,
1077+ Summary : v1alpha1.ApplicationSummary {
1078+ Images : []string {
1079+ "jannfis/foobar:1.0.0" ,
1080+ },
1081+ },
1082+ },
1083+ }
1084+
1085+ img := image .NewFromIdentifier ("foobar=jannfis/foobar:1.0.1" )
1086+
1087+ err := SetHelmImage (app , img )
1088+ require .NoError (t , err )
1089+ require .NotNil (t , app .Spec .Source .Helm )
1090+ assert .Len (t , app .Spec .Source .Helm .Parameters , 6 )
1091+
1092+ // Find first correct parameter
1093+ var tagParam v1alpha1.HelmParameter
1094+ for _ , p := range app .Spec .Source .Helm .Parameters {
1095+ if p .Name == "foobar.image.tag" {
1096+ tagParam = p
1097+ break
1098+ }
1099+ }
1100+ assert .Equal (t , "1.0.1" , tagParam .Value )
1101+
1102+ // Find second correct parameter
1103+ var tagParamTwo v1alpha1.HelmParameter
1104+ for _ , p := range app .Spec .Source .Helm .Parameters {
1105+ if p .Name == "foobar.image.tag" {
1106+ tagParamTwo = p
1107+ break
1108+ }
1109+ }
1110+ assert .Equal (t , "1.0.1" , tagParamTwo .Value )
1111+
1112+ // Find first correct parameter
1113+ var nameParam v1alpha1.HelmParameter
1114+ for _ , p := range app .Spec .Source .Helm .Parameters {
1115+ if p .Name == "foobar.image.name" {
1116+ nameParam = p
1117+ break
1118+ }
1119+ }
1120+ assert .Equal (t , "jannfis/foobar" , nameParam .Value )
1121+
1122+ // Find second correct parameter
1123+ var nameParamTwo v1alpha1.HelmParameter
1124+ for _ , p := range app .Spec .Source .Helm .Parameters {
1125+ if p .Name == "foobar2.image.name" {
1126+ nameParamTwo = p
1127+ break
1128+ }
1129+ }
1130+ assert .Equal (t , "jannfis/foobar" , nameParamTwo .Value )
1131+ })
10491132}
10501133
10511134func TestKubernetesClient (t * testing.T ) {
0 commit comments