summaryrefslogtreecommitdiffstats
path: root/test/TestIncludeMissingFileRule.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:04:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:04:50 +0000
commit782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f (patch)
tree3a88a542cd8074743d251881131510157cfc510b /test/TestIncludeMissingFileRule.py
parentInitial commit. (diff)
downloadansible-lint-782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f.tar.xz
ansible-lint-782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f.zip
Adding upstream version 4.3.7.upstream/4.3.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/TestIncludeMissingFileRule.py')
-rw-r--r--test/TestIncludeMissingFileRule.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/test/TestIncludeMissingFileRule.py b/test/TestIncludeMissingFileRule.py
new file mode 100644
index 0000000..7248fdc
--- /dev/null
+++ b/test/TestIncludeMissingFileRule.py
@@ -0,0 +1,88 @@
+from collections import namedtuple
+
+import pytest
+
+from ansiblelint.runner import Runner
+
+PlayFile = namedtuple('PlayFile', ['name', 'content'])
+
+
+PLAY_INCLUDING_PLAIN = PlayFile('playbook.yml', u'''
+- hosts: all
+ tasks:
+ - include: some_file.yml
+''')
+
+PLAY_INCLUDING_JINJA2 = PlayFile('playbook.yml', u'''
+- hosts: all
+ tasks:
+ - include: "{{ some_path }}/some_file.yml"
+''')
+
+PLAY_INCLUDING_NOQA = PlayFile('playbook.yml', u'''
+- hosts: all
+ tasks:
+ - include: some_file.yml # noqa 505
+''')
+
+PLAY_INCLUDED = PlayFile('some_file.yml', u'''
+- debug:
+ msg: 'was found & included'
+''')
+
+PLAY_HAVING_TASK = PlayFile('playbook.yml', u'''
+- name: Play
+ hosts: all
+ pre_tasks:
+ tasks:
+ - name: Ping
+ ping:
+''')
+
+
+@pytest.fixture
+def play_file_path(tmp_path):
+ p = tmp_path / 'playbook.yml'
+ return str(p)
+
+
+@pytest.fixture
+def runner(play_file_path, default_rules_collection):
+ return Runner(default_rules_collection, play_file_path, [], [], [])
+
+
+@pytest.fixture
+def _play_files(tmp_path, request):
+ if request.param is None:
+ return
+ for play_file in request.param:
+ p = tmp_path / play_file.name
+ p.write_text(play_file.content)
+
+
+@pytest.mark.parametrize(
+ '_play_files', (pytest.param([PLAY_INCLUDING_PLAIN], id='referenced file missing'), ),
+ indirect=['_play_files']
+)
+@pytest.mark.usefixtures('_play_files')
+def test_include_file_missing(runner):
+ results = str(runner.run())
+ assert 'referenced missing file in' in results
+ assert 'playbook.yml' in results
+ assert 'some_file.yml' in results
+
+
+@pytest.mark.parametrize(
+ '_play_files',
+ (
+ pytest.param([PLAY_INCLUDING_PLAIN, PLAY_INCLUDED], id='File Exists'),
+ pytest.param([PLAY_INCLUDING_JINJA2], id='JINJA2 in reference'),
+ pytest.param([PLAY_INCLUDING_NOQA], id='NOQA was used'),
+ pytest.param([PLAY_HAVING_TASK], id='Having a task')
+ ),
+ indirect=['_play_files']
+)
+@pytest.mark.usefixtures('_play_files')
+def test_cases_that_do_not_report(runner):
+ results = str(runner.run())
+ assert 'referenced missing file in' not in results