Skip to content

Commit

Permalink
Add test case to validate test lineinfile
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AndreMarcel99 authored and fernandofloresg committed Dec 18, 2024
1 parent fbc587b commit 6407365
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trivial:
- zos_lineinfile - Add test cases to validate use of advanced regular expression.
(https://github.com/ansible-collections/ibm_zos_core/pull/1842).
36 changes: 36 additions & 0 deletions tests/functional/modules/test_zos_lineinfile_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@
export ZOAU_ROOT
export _BPXK_AUTOCVT"""

TEST_CONTENT_ADVANCED_REGULAR_EXPRESSION="""if [ -z STEPLIB ] && tty -s;
then
D160882
D160882
ED160882
export STEPLIB=none
exec -a 0 SHELL
fi
PATH=/usr/lpp/zoautil/v100/bin:/usr/lpp/rsusr/ported/bin:/bin:/var/bin
export PATH
ZOAU_ROOT=/usr/lpp/zoautil/v100
export ZOAU_ROOT
export _BPXK_AUTOCVT"""

EXPECTED_REPLACE="""if [ -z STEPLIB ] && tty -s;
then
export STEPLIB=none
Expand Down Expand Up @@ -538,6 +552,28 @@ def test_uss_line_absent(ansible_zos_module):
remove_uss_environment(ansible_zos_module, full_path)


@pytest.mark.uss
def test_uss_advanced_regular_expression_absent(ansible_zos_module):
hosts = ansible_zos_module
params = {
"regexp":"[A-Za-z][0-9]{6}",
"state":"absent"
}
full_path = get_random_file_name(dir=TMP_DIRECTORY)
content = TEST_CONTENT_ADVANCED_REGULAR_EXPRESSION
try:
set_uss_environment(ansible_zos_module, content, full_path)
params["path"] = full_path
results = hosts.all.zos_lineinfile(**params)
for result in results.contacted.values():
assert result.get("changed") == 1
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
for result in results.contacted.values():
assert result.get("stdout") == TEST_CONTENT
finally:
remove_uss_environment(ansible_zos_module, full_path)


@pytest.mark.uss
def test_uss_line_replace_quoted_escaped(ansible_zos_module):
hosts = ansible_zos_module
Expand Down

0 comments on commit 6407365

Please sign in to comment.