@@ -261,3 +261,135 @@ def test_get_params_from_args_with_multiple_declarations(self):
261
261
262
262
# set auto_dict back to default
263
263
mockarg .auto_dict = False
264
+
265
+ def test_correctly_process_inherit_env_when_no_parameters_set (self ):
266
+ """test_correctly_process_inherit_env_when_no_parameters_set
267
+
268
+ This tests that we still correctly pass through the environment variables
269
+ when --inherit-env is set and we run an action that does not have parameters
270
+ """
271
+
272
+ runner = RunnerType ()
273
+ runner .runner_parameters = {}
274
+
275
+ action = Action ()
276
+ action .ref = "test.action"
277
+
278
+ subparser = mock .Mock ()
279
+ command = ActionRunCommand (action , self , subparser , name = "test" )
280
+
281
+ mockarg = mock .Mock ()
282
+ mockarg .inherit_env = True
283
+ mockarg .auto_dict = True
284
+ mockarg .parameters = []
285
+
286
+ k1 = "key1"
287
+ v1 = "value1"
288
+ k2 = "key2"
289
+ v2 = "value2"
290
+
291
+ with mock .patch ("os.environ.copy" ) as mockCopy :
292
+ mockCopy .return_value = {k1 : v1 , k2 : v2 }
293
+ param = command ._get_action_parameters_from_args (
294
+ action = action , runner = runner , args = mockarg
295
+ )
296
+
297
+ self .assertIn ("env" , param )
298
+
299
+ env_params = param ["env" ]
300
+ self .assertIn (k1 , env_params )
301
+ self .assertIn (k2 , env_params )
302
+ self .assertEqual (v1 , env_params [k1 ])
303
+ self .assertEqual (v2 , env_params [k2 ])
304
+
305
+ def test_correctly_process_inherit_env_when_parameters_set (self ):
306
+ """test_correctly_process_inherit_env_when_parameters_set
307
+
308
+ This tests that we still correctly pass through the environment variables
309
+ when --inherit-env is set and we run an action that has action parameters set
310
+ """
311
+
312
+ runner = RunnerType ()
313
+ runner .runner_parameters = {}
314
+
315
+ action = Action ()
316
+ action .ref = "test.action"
317
+ action .parameters = {
318
+ "param_string" : {"type" : "string" },
319
+ "param_array" : {"type" : "array" },
320
+ "param_array_of_dicts" : {"type" : "array" },
321
+ }
322
+
323
+ subparser = mock .Mock ()
324
+ command = ActionRunCommand (action , self , subparser , name = "test" )
325
+
326
+ p_string = "param_string"
327
+ p_array = "param_array"
328
+ p_ra_dicts = "param_array_of_dicts"
329
+ mockarg = mock .Mock ()
330
+ mockarg .inherit_env = True
331
+ mockarg .auto_dict = True
332
+ mockarg .parameters = [
333
+ f"{ p_string } =hoge" ,
334
+ f"{ p_array } =foo,bar" ,
335
+ f"{ p_ra_dicts } =foo:1,bar:2" ,
336
+ ]
337
+
338
+ k1 = "key1"
339
+ v1 = "value1"
340
+ k2 = "key2"
341
+ v2 = "value2"
342
+
343
+ with mock .patch ("os.environ.copy" ) as mockCopy :
344
+ mockCopy .return_value = {k1 : v1 , k2 : v2 }
345
+ param = command ._get_action_parameters_from_args (
346
+ action = action , runner = runner , args = mockarg
347
+ )
348
+
349
+ self .assertIn ("env" , param )
350
+
351
+ env_params = param ["env" ]
352
+ self .assertIn (k1 , env_params )
353
+ self .assertIn (k2 , env_params )
354
+ self .assertEqual (v1 , env_params [k1 ])
355
+ self .assertEqual (v2 , env_params [k2 ])
356
+ self .assertIn (p_string , param )
357
+ self .assertEqual ("hoge" , param [p_string ])
358
+ self .assertIn (p_array , param )
359
+ self .assertIn ("foo" , param [p_array ])
360
+ self .assertIn ("bar" , param [p_array ])
361
+ self .assertIn (p_ra_dicts , param )
362
+ self .assertDictEqual ({"foo" : "1" , "bar" : "2" }, param [p_ra_dicts ][0 ])
363
+
364
+ def test_correctly_generate_empty_params_no_inherit_empty_parameters (self ):
365
+ """test_correctly_generate_empty_params_no_inherit_empty_parameters
366
+
367
+ Verifies that we return an empty dict when we do not provide inherit env and parameters
368
+ """
369
+
370
+ runner = RunnerType ()
371
+ runner .runner_parameters = {}
372
+
373
+ action = Action ()
374
+ action .ref = "test.action"
375
+
376
+ subparser = mock .Mock ()
377
+ command = ActionRunCommand (action , self , subparser , name = "test" )
378
+
379
+ mockarg = mock .Mock ()
380
+ mockarg .inherit_env = False
381
+ mockarg .auto_dict = True
382
+ mockarg .parameters = []
383
+
384
+ k1 = "key1"
385
+ v1 = "value1"
386
+ k2 = "key2"
387
+ v2 = "value2"
388
+
389
+ with mock .patch ("os.environ.copy" ) as mockCopy :
390
+ mockCopy .return_value = {k1 : v1 , k2 : v2 }
391
+ param = command ._get_action_parameters_from_args (
392
+ action = action , runner = runner , args = mockarg
393
+ )
394
+
395
+ self .assertDictEqual ({}, param )
0 commit comments