@@ -144,3 +144,127 @@ func TestBuildArgsArrayAndEnv(t *testing.T) {
144144 assert .ElementsMatch (t , expectedArgs , args )
145145 assert .ElementsMatch (t , expectedEnv , env )
146146}
147+
148+ func TestMapToExpandableStringSliceWithHyphenConversion (t * testing.T ) {
149+ // Test that build args with infra.parameters. prefix get hyphens converted to underscores
150+ buildArgs := map [string ]string {
151+ "ARG1" : "value1" ,
152+ "ARG2" : "{infra.parameters.param-name}" ,
153+ "ARG3" : "{infra.parameters.another-param-name}" ,
154+ "ARG4" : "{some.other.param-name}" , // Should NOT be converted (no infra.parameters. prefix)
155+ "ARG5" : "regular-value-with-hyphens" , // Should NOT be converted (not a parameter reference)
156+ "ARG6" : "{infra.parameters.param_underscore}" , // Should remain unchanged (already has underscore)
157+ "ARG7" : "{infra.parameters.param-name-with-suffix}" ,
158+ "ARG8" : "" ,
159+ }
160+
161+ result := mapToExpandableStringSliceWithHyphenConversion (buildArgs , "=" )
162+
163+ // Convert result to strings for easier comparison using identity mapping
164+ resultStrings := make ([]string , len (result ))
165+ for i , item := range result {
166+ resultStrings [i ] = item .MustEnvsubst (func (name string ) string { return "${" + name + "}" })
167+ }
168+
169+ expected := []string {
170+ "ARG1=value1" ,
171+ "ARG2={infra.parameters.param_name}" , // Hyphen converted to underscore
172+ "ARG3={infra.parameters.another_param_name}" , // Hyphens converted to underscores
173+ "ARG4={some.other.param-name}" , // NOT converted (wrong prefix)
174+ "ARG5=regular-value-with-hyphens" , // NOT converted (not a parameter reference)
175+ "ARG6={infra.parameters.param_underscore}" , // Unchanged (already has underscore)
176+ "ARG7={infra.parameters.param_name_with_suffix}" , // All hyphens converted
177+ "ARG8" , // Empty value
178+ }
179+
180+ assert .ElementsMatch (t , expected , resultStrings )
181+ }
182+
183+ func TestEvaluateArgsWithConfigHyphenHandling (t * testing.T ) {
184+ // Test integration with evaluateArgsWithConfig to ensure hyphens in parameter names
185+ // get converted to underscores in infra.parameters references
186+ manifest := apphost.Manifest {
187+ Resources : map [string ]* apphost.Resource {
188+ "param-with-hyphens" : {
189+ Type : "parameter.v0" ,
190+ Value : "{param-with-hyphens.inputs.inputParam}" ,
191+ Inputs : map [string ]apphost.Input {
192+ "inputParam" : {
193+ Type : "string" ,
194+ },
195+ },
196+ },
197+ },
198+ }
199+
200+ args := map [string ]string {
201+ "BUILD_ARG1" : "{param-with-hyphens.value}" ,
202+ "BUILD_ARG2" : "constant-value" ,
203+ }
204+
205+ // Evaluate args first (this should produce {infra.parameters.param-with-hyphens})
206+ evaluatedArgs , err := evaluateArgsWithConfig (manifest , args )
207+ require .NoError (t , err )
208+
209+ // Now apply hyphen conversion when creating expandable strings
210+ result := mapToExpandableStringSliceWithHyphenConversion (evaluatedArgs , "=" )
211+
212+ // Convert to strings for verification
213+ resultStrings := make ([]string , len (result ))
214+ for i , item := range result {
215+ resultStrings [i ] = item .MustEnvsubst (func (name string ) string { return "${" + name + "}" })
216+ }
217+
218+ expected := []string {
219+ "BUILD_ARG1={infra.parameters.param_with_hyphens}" , // Hyphen converted to underscore
220+ "BUILD_ARG2=constant-value" , // Unchanged (not a parameter reference)
221+ }
222+
223+ assert .ElementsMatch (t , expected , resultStrings )
224+ }
225+
226+ func TestConvertHyphensInInfraParameters (t * testing.T ) {
227+ tests := []struct {
228+ name string
229+ input string
230+ expected string
231+ }{
232+ {
233+ name : "infra.parameters with hyphens" ,
234+ input : "{infra.parameters.my-param-name}" ,
235+ expected : "{infra.parameters.my_param_name}" ,
236+ },
237+ {
238+ name : "infra.parameters with underscores" ,
239+ input : "{infra.parameters.my_param_name}" ,
240+ expected : "{infra.parameters.my_param_name}" ,
241+ },
242+ {
243+ name : "non-infra parameter reference" ,
244+ input : "{some.other.param-name}" ,
245+ expected : "{some.other.param-name}" ,
246+ },
247+ {
248+ name : "regular string with hyphens" ,
249+ input : "regular-string-with-hyphens" ,
250+ expected : "regular-string-with-hyphens" ,
251+ },
252+ {
253+ name : "empty string" ,
254+ input : "" ,
255+ expected : "" ,
256+ },
257+ {
258+ name : "malformed parameter reference" ,
259+ input : "{infra.parameters.param-name" ,
260+ expected : "{infra.parameters.param-name" ,
261+ },
262+ }
263+
264+ for _ , tt := range tests {
265+ t .Run (tt .name , func (t * testing.T ) {
266+ result := convertHyphensInInfraParameters (tt .input )
267+ assert .Equal (t , tt .expected , result )
268+ })
269+ }
270+ }
0 commit comments