diff options
author | Abhijeet Kasurde <akasurde@redhat.com> | 2021-06-02 10:09:42 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-02 10:09:42 +0530 |
commit | be9f8c69d1e968c8342449d7e0ab5504a3f8a5c2 (patch) | |
tree | eaa427936dbaf9fa410c92869d9b41865351eb66 /test/units/modules | |
parent | 805799ac8bca0bdd18e8f9b21332b5b6d4d43845 (diff) | |
download | ansible-be9f8c69d1e968c8342449d7e0ab5504a3f8a5c2.tar.gz |
unarchive: Fail when zipinfo is not available (#74632)
Fixes: #39029
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Diffstat (limited to 'test/units/modules')
-rw-r--r-- | test/units/modules/test_unarchive.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/units/modules/test_unarchive.py b/test/units/modules/test_unarchive.py new file mode 100644 index 0000000000..3550e4cc34 --- /dev/null +++ b/test/units/modules/test_unarchive.py @@ -0,0 +1,76 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + + +import pytest + +from ansible.modules.unarchive import ZipArchive, TgzArchive + + +class AnsibleModuleExit(Exception): + def __init__(self, *args, **kwargs): + self.args = args + self.kwargs = kwargs + + +class ExitJson(AnsibleModuleExit): + pass + + +class FailJson(AnsibleModuleExit): + pass + + +@pytest.fixture +def fake_ansible_module(): + return FakeAnsibleModule() + + +class FakeAnsibleModule: + def __init__(self): + self.params = {} + self.tmpdir = None + + def exit_json(self, *args, **kwargs): + raise ExitJson(*args, **kwargs) + + def fail_json(self, *args, **kwargs): + raise FailJson(*args, **kwargs) + + +class TestCaseZipArchive: + def test_no_zip_binary(self, mocker, fake_ansible_module): + mocker.patch("ansible.modules.unarchive.get_bin_path", side_effect=ValueError) + fake_ansible_module.params = { + "extra_opts": "", + "exclude": "", + "include": "", + } + with pytest.raises(FailJson) as exec_info: + z = ZipArchive( + src="", + b_dest="", + file_args="", + module=fake_ansible_module, + ) + assert "Unable to find required" in exec_info.value.kwargs["msg"] + + +class TestCaseTgzArchive: + def test_no_tar_binary(self, mocker, fake_ansible_module): + mocker.patch("ansible.modules.unarchive.get_bin_path", side_effect=ValueError) + fake_ansible_module.params = { + "extra_opts": "", + "exclude": "", + "include": "", + } + fake_ansible_module.check_mode = False + with pytest.raises(FailJson) as exec_info: + z = TgzArchive( + src="", + b_dest="", + file_args="", + module=fake_ansible_module, + ) + assert "Unable to find required" in exec_info.value.kwargs["msg"] |