Skip to content

Commit

Permalink
Add a unit test to test copy_tree_with_replace with the newrolename arg
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrosi committed Apr 21, 2021
1 parent f2269c8 commit f8f7d36
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions tests/unit/test_lsr_role2collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace = os.environ.get("COLLECTION_NAMESPACE", "fedora")
collection_name = os.environ.get("COLLECTION_NAME", "system_roles")
rolename = "systemrole"
newrolename = "newsystemrole"
prefix = namespace + "." + collection_name
prefixdot = prefix + "."

Expand Down Expand Up @@ -279,6 +280,125 @@ def test_copy_tree_with_replace(self):
)
shutil.rmtree(coll_path)

def test_copy_tree_with_replace_with_newrolename(self):
"""test copy_tree_with_replace"""

pre_params = [
{
"key": "import_role",
"subkey": "name:",
"value": "linux-system-roles",
"delim": ".",
"subvalue": rolename,
},
{
"key": "include_role",
"subkey": "name:",
"value": "linux-system-roles",
"delim": ".",
"subvalue": rolename,
},
{
"key": "include_role",
"subkey": "name:",
"value": '"{{ role_path }}/roles',
"delim": "/",
"subvalue": '__subrole_with__"',
},
{
"key": "include_role",
"subkey": "name:",
"value": '"{{ role_path }}/roles',
"delim": "/",
"subvalue": 'subrole_no__"',
},
{
"key": "include_tasks",
"subkey": "-",
"value": '"{{ role_path }}/roles/subrole/tasks',
"delim": "/",
"subvalue": 'mytask.yml"',
},
{
"key": "include_vars",
"subkey": "-",
"value": '"{{ role_path }}/roles/subrole/vars',
"delim": "/",
"subvalue": 'myvar.yml"',
},
]
post_params = [
{
"key": "import_role",
"subkey": "name:",
"value": prefix,
"delim": ".",
"subvalue": newrolename,
},
{
"key": "include_role",
"subkey": "name:",
"value": prefix,
"delim": ".",
"subvalue": newrolename,
},
{
"key": "include_role",
"subkey": "name:",
"value": '"' + prefix,
"delim": ".",
"subvalue": '__subrole_with__"',
},
{
"key": "include_role",
"subkey": "name:",
"value": '"' + prefix,
"delim": ".",
"subvalue": 'subrole_no__"',
},
{
"key": "include_tasks",
"subkey": "-",
"value": '"{{ role_path }}/roles/subrole/tasks',
"delim": "/",
"subvalue": 'mytask.yml"',
},
{
"key": "include_vars",
"subkey": "-",
"value": '"{{ role_path }}/roles/subrole/vars',
"delim": "/",
"subvalue": 'myvar.yml"',
},
]
MYTUPLE = ("tasks",)
tmpdir = tempfile.TemporaryDirectory()
role_path = Path(tmpdir.name) / "linux-system-roles" / rolename
coll_path = (
Path(dest_path) / "ansible_collections" / namespace / collection_name
)
self.create_test_tree(
role_path / "tasks", test_yaml_str, pre_params, ".yml", is_vertical=False
)
transformer_args = {
"namespace": namespace,
"collection": collection_name,
"prefix": prefixdot,
"subrole_prefix": "",
"replace_dot": "_",
"role_modules": set(),
"src_owner": "linux-system-roles",
"top_dir": dest_path,
}
copy_tree_with_replace(
role_path, coll_path, rolename, newrolename, MYTUPLE, transformer_args, isrole=True
)
test_path = coll_path / "roles" / newrolename / "tasks"
self.check_test_tree(
test_path, test_yaml_str, post_params, ".yml", is_vertical=False
)
shutil.rmtree(coll_path)

def test_import_replace(self):
module_names = ["util0", "util1"]
src_module_utils = []
Expand Down

0 comments on commit f8f7d36

Please sign in to comment.