@@ -307,31 +307,76 @@ def test_getLaunchConf(default_yml, os_env, output):
307
307
environ .getLaunchConf (vars_scope )
308
308
assert vars_scope ["splunk" ] == output
309
309
310
+ @pytest .mark .parametrize (("value" , "separator" , "output" ),
311
+ [
312
+ # Check null value
313
+ (None , "," , []),
314
+ # Check empty value
315
+ ("" , "," , []),
316
+ # Check string value
317
+ ("a" , "," , ["a" ]),
318
+ # Check comma separated string value
319
+ ("a,b,c" , "," , ["a" , "b" , "c" ]),
320
+ # Check list value
321
+ (["a" ], "," , ["a" ]),
322
+ (["a" , "b" , "c" ], "," , ["a" , "b" , "c" ])
323
+ ]
324
+ )
325
+ def test_ensureListValue (value , separator , output ):
326
+ result = environ .ensureListValue (value , separator )
327
+ assert result == output
328
+
329
+ @pytest .mark .parametrize (("value" , "separator" , "output" ),
330
+ [
331
+ # Check null value
332
+ (None , "," , []),
333
+ # Check empty value
334
+ ("" , "," , []),
335
+ # Check string value
336
+ ("a" , "," , ["a" ]),
337
+ # Check comma separated string value
338
+ ("a,b,c" , "," , ["a" , "b" , "c" ]),
339
+ # Check comma separated string value with whitespaces
340
+ (" a, b,c " , "," , ["a" , "b" , "c" ]),
341
+ ]
342
+ )
343
+ def test_splitAndStrip (value , separator , output ):
344
+ result = environ .splitAndStrip (value , separator )
345
+ assert result == output
346
+
310
347
@pytest .mark .parametrize (("default_yml" , "os_env" , "output" ),
311
348
[
312
349
# Check null parameters
313
- ({}, {}, {"ansible_pre_tasks" : None , "ansible_post_tasks" : None , "ansible_environment" : {}}),
350
+ ({}, {}, {"ansible_pre_tasks" : [] , "ansible_post_tasks" : [] , "ansible_environment" : {}}),
314
351
# Check ansible_pre_tasks using defaults or env vars
315
- ({"ansible_pre_tasks" : "" }, {}, {"ansible_pre_tasks" : "" , "ansible_post_tasks" : None , "ansible_environment" : {}}),
316
- ({"ansible_pre_tasks" : "a" }, {}, {"ansible_pre_tasks" : "a" , "ansible_post_tasks" : None , "ansible_environment" : {}}),
317
- ({"ansible_pre_tasks" : "a,b,c" }, {}, {"ansible_pre_tasks" : "a,b,c" , "ansible_post_tasks" : None , "ansible_environment" : {}}),
318
- ({}, {"SPLUNK_ANSIBLE_PRE_TASKS" : "d" }, {"ansible_pre_tasks" : "d" , "ansible_post_tasks" : None , "ansible_environment" : {}}),
319
- ({}, {"SPLUNK_ANSIBLE_PRE_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : "e,f,g" , "ansible_post_tasks" : None , "ansible_environment" : {}}),
320
- ({"ansible_pre_tasks" : "a,b,c" }, {"SPLUNK_ANSIBLE_PRE_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : "e,f,g" , "ansible_post_tasks" : None , "ansible_environment" : {}}),
352
+ ({"ansible_pre_tasks" : "" }, {}, {"ansible_pre_tasks" : [], "ansible_post_tasks" : [], "ansible_environment" : {}}),
353
+ ({"ansible_pre_tasks" : None }, {}, {"ansible_pre_tasks" : [], "ansible_post_tasks" : [], "ansible_environment" : {}}),
354
+ ({"ansible_pre_tasks" : "a" }, {}, {"ansible_pre_tasks" : ["a" ], "ansible_post_tasks" : [], "ansible_environment" : {}}),
355
+ ({"ansible_pre_tasks" : ["a" ]}, {}, {"ansible_pre_tasks" : ["a" ], "ansible_post_tasks" : [], "ansible_environment" : {}}),
356
+ ({"ansible_pre_tasks" : "a,b,c" }, {}, {"ansible_pre_tasks" : ["a" ,"b" ,"c" ], "ansible_post_tasks" : [], "ansible_environment" : {}}),
357
+ ({"ansible_pre_tasks" : ["a" ,"b" ,"c" ]}, {}, {"ansible_pre_tasks" : ["a" ,"b" ,"c" ], "ansible_post_tasks" : [], "ansible_environment" : {}}),
358
+ ({}, {"SPLUNK_ANSIBLE_PRE_TASKS" : "d" }, {"ansible_pre_tasks" : ["d" ], "ansible_post_tasks" : [], "ansible_environment" : {}}),
359
+ ({}, {"SPLUNK_ANSIBLE_PRE_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : ["e" ,"f" ,"g" ], "ansible_post_tasks" : [], "ansible_environment" : {}}),
360
+ ({"ansible_pre_tasks" : "a,b,c" }, {"SPLUNK_ANSIBLE_PRE_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : ["e" ,"f" ,"g" ], "ansible_post_tasks" : [], "ansible_environment" : {}}),
361
+ ({"ansible_pre_tasks" : ["a" ,"b" ,"c" ]}, {"SPLUNK_ANSIBLE_PRE_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : ["e" ,"f" ,"g" ], "ansible_post_tasks" : [], "ansible_environment" : {}}),
321
362
# Check ansible_post_tasks using defaults or env vars
322
- ({"ansible_post_tasks" : "" }, {}, {"ansible_pre_tasks" : None , "ansible_post_tasks" : "" , "ansible_environment" : {}}),
323
- ({"ansible_post_tasks" : "a" }, {}, {"ansible_pre_tasks" : None , "ansible_post_tasks" : "a" , "ansible_environment" : {}}),
324
- ({"ansible_post_tasks" : "a,b,c" }, {}, {"ansible_pre_tasks" : None , "ansible_post_tasks" : "a,b,c" , "ansible_environment" : {}}),
325
- ({}, {"SPLUNK_ANSIBLE_POST_TASKS" : "d" }, {"ansible_pre_tasks" : None , "ansible_post_tasks" : "d" , "ansible_environment" : {}}),
326
- ({}, {"SPLUNK_ANSIBLE_POST_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : None , "ansible_post_tasks" : "e,f,g" , "ansible_environment" : {}}),
327
- ({"ansible_post_tasks" : "a,b,c" }, {"SPLUNK_ANSIBLE_POST_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : None , "ansible_post_tasks" : "e,f,g" , "ansible_environment" : {}}),
363
+ ({"ansible_post_tasks" : "" }, {}, {"ansible_pre_tasks" : [], "ansible_post_tasks" : [], "ansible_environment" : {}}),
364
+ ({"ansible_post_tasks" : None }, {}, {"ansible_pre_tasks" : [], "ansible_post_tasks" : [], "ansible_environment" : {}}),
365
+ ({"ansible_post_tasks" : "a" }, {}, {"ansible_pre_tasks" : [], "ansible_post_tasks" : ["a" ], "ansible_environment" : {}}),
366
+ ({"ansible_post_tasks" : ["a" ]}, {}, {"ansible_pre_tasks" : [], "ansible_post_tasks" : ["a" ], "ansible_environment" : {}}),
367
+ ({"ansible_post_tasks" : "a,b,c" }, {}, {"ansible_pre_tasks" : [], "ansible_post_tasks" : ["a" ,"b" ,"c" ], "ansible_environment" : {}}),
368
+ ({"ansible_post_tasks" : ["a" ,"b" ,"c" ]}, {}, {"ansible_pre_tasks" : [], "ansible_post_tasks" : ["a" ,"b" ,"c" ], "ansible_environment" : {}}),
369
+ ({}, {"SPLUNK_ANSIBLE_POST_TASKS" : "d" }, {"ansible_pre_tasks" : [], "ansible_post_tasks" : ["d" ], "ansible_environment" : {}}),
370
+ ({}, {"SPLUNK_ANSIBLE_POST_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : [], "ansible_post_tasks" : ["e" ,"f" ,"g" ], "ansible_environment" : {}}),
371
+ ({"ansible_post_tasks" : "a,b,c" }, {"SPLUNK_ANSIBLE_POST_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : [], "ansible_post_tasks" : ["e" ,"f" ,"g" ], "ansible_environment" : {}}),
372
+ ({"ansible_post_tasks" : ["a" ,"b" ,"c" ]}, {"SPLUNK_ANSIBLE_POST_TASKS" : "e,f,g" }, {"ansible_pre_tasks" : [], "ansible_post_tasks" : ["e" ,"f" ,"g" ], "ansible_environment" : {}}),
328
373
# Check ansible_environment using defaults or env vars
329
- ({"ansible_environment" : None }, {}, {"ansible_pre_tasks" : None , "ansible_post_tasks" : None , "ansible_environment" : {}}),
330
- ({"ansible_environment" : {"a" : "b" }}, {}, {"ansible_pre_tasks" : None , "ansible_post_tasks" : None , "ansible_environment" : {"a" : "b" }}),
331
- ({"ansible_environment" : {"a" : "b" , "d" : "e" }}, {}, {"ansible_pre_tasks" : None , "ansible_post_tasks" : None , "ansible_environment" : {"a" : "b" , "d" : "e" }}),
332
- ({}, {"SPLUNK_ANSIBLE_ENV" : "a=b" }, {"ansible_pre_tasks" : None , "ansible_post_tasks" : None , "ansible_environment" : {"a" : "b" }}),
333
- ({}, {"SPLUNK_ANSIBLE_ENV" : "a=b,x=y" }, {"ansible_pre_tasks" : None , "ansible_post_tasks" : None , "ansible_environment" : {"a" : "b" , "x" : "y" }}),
334
- ({"ansible_environment" : {"a" : "c" , "d" : "e" }}, {"SPLUNK_ANSIBLE_ENV" : "a=b,x=y" }, {"ansible_pre_tasks" : None , "ansible_post_tasks" : None , "ansible_environment" : {"a" : "b" , "d" : "e" , "x" : "y" }}),
374
+ ({"ansible_environment" : None }, {}, {"ansible_pre_tasks" : [] , "ansible_post_tasks" : [] , "ansible_environment" : {}}),
375
+ ({"ansible_environment" : {"a" : "b" }}, {}, {"ansible_pre_tasks" : [] , "ansible_post_tasks" : [] , "ansible_environment" : {"a" : "b" }}),
376
+ ({"ansible_environment" : {"a" : "b" , "d" : "e" }}, {}, {"ansible_pre_tasks" : [] , "ansible_post_tasks" : [] , "ansible_environment" : {"a" : "b" , "d" : "e" }}),
377
+ ({}, {"SPLUNK_ANSIBLE_ENV" : "a=b" }, {"ansible_pre_tasks" : [] , "ansible_post_tasks" : [] , "ansible_environment" : {"a" : "b" }}),
378
+ ({}, {"SPLUNK_ANSIBLE_ENV" : "a=b,x=y" }, {"ansible_pre_tasks" : [] , "ansible_post_tasks" : [] , "ansible_environment" : {"a" : "b" , "x" : "y" }}),
379
+ ({"ansible_environment" : {"a" : "c" , "d" : "e" }}, {"SPLUNK_ANSIBLE_ENV" : "a=b,x=y" }, {"ansible_pre_tasks" : [] , "ansible_post_tasks" : [] , "ansible_environment" : {"a" : "b" , "d" : "e" , "x" : "y" }}),
335
380
]
336
381
)
337
382
def test_getAnsibleContext (default_yml , os_env , output ):
0 commit comments