Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new test for 'import_tasks'
Browse files Browse the repository at this point in the history
europ committed Mar 8, 2021
1 parent dd4bf59 commit a4ee5ea
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/TestImportTasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""Calling 'import_task' from multiple files in different directories."""
import os
import shutil
import tempfile
import textwrap

import pytest

from ansiblelint.runner import Runner

LAYOUT = {
'directories': ['tasks', 'tasks/subtasks'],
'files': {
'main.yml': textwrap.dedent(
"""\
---
- hosts: target
gather_facts: false
tasks:
- name: from main import task 1
import_tasks: tasks/task_1.yml
"""
),
'tasks/task_1.yml': textwrap.dedent(
"""\
---
- name: from task 1 import task 2
import_tasks: tasks/task_2.yml
"""
),
'tasks/task_2.yml': textwrap.dedent(
"""\
---
- name: from task 2 import subtask 1
import_tasks: tasks/subtasks/subtask_1.yml
"""
),
'tasks/subtasks/subtask_1.yml': textwrap.dedent(
"""\
---
- name: from subtask 1 import subtask 2
import_tasks: tasks/subtasks/subtask_2.yml
"""
),
'tasks/subtasks/subtask_2.yml': textwrap.dedent(
"""\
---
- name: from subtask 2 do something
debug:
msg: |
Something...
"""
),
},
}


@pytest.mark.xfail
def test_import_tasks(default_rules_collection):
"""Calling 'import_task' from multiple files in different directories."""
root_dir_path = tempfile.mkdtemp()

for directory in LAYOUT['directories']:
os.makedirs(os.path.join(root_dir_path, directory), exist_ok=True)

for file_path, file_content in LAYOUT['files'].items():
open(os.path.join(root_dir_path, file_path), 'w').write(file_content)

result = Runner(root_dir_path, rules=default_rules_collection).run()

shutil.rmtree(root_dir_path)

assert len(result) == 0

0 comments on commit a4ee5ea

Please sign in to comment.