diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:04:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:04:50 +0000 |
commit | 782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f (patch) | |
tree | 3a88a542cd8074743d251881131510157cfc510b /test/TestImportWithMalformed.py | |
parent | Initial commit. (diff) | |
download | ansible-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 '')
-rw-r--r-- | test/TestImportWithMalformed.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/TestImportWithMalformed.py b/test/TestImportWithMalformed.py new file mode 100644 index 0000000..4f5425c --- /dev/null +++ b/test/TestImportWithMalformed.py @@ -0,0 +1,65 @@ +from collections import namedtuple + +import pytest + +from ansiblelint.runner import Runner + +PlayFile = namedtuple('PlayFile', ['name', 'content']) + + +IMPORT_TASKS_MAIN = PlayFile('import-tasks-main.yml', ''' +- oops this is invalid +''') + +IMPORT_SHELL_PIP = PlayFile('import-tasks-main.yml', ''' +- shell: pip +''') + +PLAY_IMPORT_TASKS = PlayFile('playbook.yml', ''' +- hosts: all + tasks: + - import_tasks: import-tasks-main.yml +''') + + +@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([IMPORT_SHELL_PIP, PLAY_IMPORT_TASKS], id='Import shell w/ pip'), + pytest.param( + [IMPORT_TASKS_MAIN, PLAY_IMPORT_TASKS], + id='import_tasks w/ malformed import', + marks=pytest.mark.xfail( + reason='Garbage non-tasks sequence is not being ' + 'properly processed. Ref: ' + 'https://github.com/ansible/ansible-lint/issues/707', + raises=AttributeError, + ), + ), + ), + indirect=['_play_files'] +) +@pytest.mark.usefixtures('_play_files') +def test_import_tasks_with_malformed_import(runner): + results = str(runner.run()) + assert 'only when shell functionality is required' in results |