diff options
Diffstat (limited to '')
-rw-r--r-- | test/TestIncludeMissingFileRule.py | 88 |
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 |