Skip to content

Commit 083ad98

Browse files
AndreMarcel99fernandofloresg
authored andcommitted
Add test case to validate test lineinfile
Add fragment Update tests/functional/modules/test_zos_lineinfile_func.py Co-authored-by: Fernando Flores <[email protected]> Update changelogs/fragments/1842-Add_test_case_to_validate_advance_regular_expression.yml Co-authored-by: Fernando Flores <[email protected]> Update test_zos_lineinfile_func.py
1 parent 3db400b commit 083ad98

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trivial:
2+
- zos_lineinfile - Add test cases to validate use of advanced regular expression.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/1842).

tests/functional/modules/test_zos_lineinfile_func.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@
6161
export ZOAU_ROOT
6262
export _BPXK_AUTOCVT"""
6363

64+
TEST_CONTENT_ADVANCED_REGULAR_EXPRESSION="""if [ -z STEPLIB ] && tty -s;
65+
then
66+
D160882
67+
D160882
68+
ED160882
69+
export STEPLIB=none
70+
exec -a 0 SHELL
71+
fi
72+
PATH=/usr/lpp/zoautil/v100/bin:/usr/lpp/rsusr/ported/bin:/bin:/var/bin
73+
export PATH
74+
ZOAU_ROOT=/usr/lpp/zoautil/v100
75+
export ZOAU_ROOT
76+
export _BPXK_AUTOCVT"""
77+
6478
EXPECTED_REPLACE="""if [ -z STEPLIB ] && tty -s;
6579
then
6680
export STEPLIB=none
@@ -538,6 +552,28 @@ def test_uss_line_absent(ansible_zos_module):
538552
remove_uss_environment(ansible_zos_module, full_path)
539553

540554

555+
@pytest.mark.uss
556+
def test_uss_advanced_regular_expression_absent(ansible_zos_module):
557+
hosts = ansible_zos_module
558+
params = {
559+
"regexp":"[A-Za-z][0-9]{6}",
560+
"state":"absent"
561+
}
562+
full_path = get_random_file_name(dir=TMP_DIRECTORY)
563+
content = TEST_CONTENT_ADVANCED_REGULAR_EXPRESSION
564+
try:
565+
set_uss_environment(ansible_zos_module, content, full_path)
566+
params["path"] = full_path
567+
results = hosts.all.zos_lineinfile(**params)
568+
for result in results.contacted.values():
569+
assert result.get("changed") == 1
570+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
571+
for result in results.contacted.values():
572+
assert result.get("stdout") == TEST_CONTENT
573+
finally:
574+
remove_uss_environment(ansible_zos_module, full_path)
575+
576+
541577
@pytest.mark.uss
542578
def test_uss_line_replace_quoted_escaped(ansible_zos_module):
543579
hosts = ansible_zos_module

0 commit comments

Comments
 (0)