def test_virtual_function(subtests): """ Test Ansible module __virtual__ when ansible is not installed on the minion. :return: """ with subtests.test("missing ansible binary"): with patch("salt.utils.path.which", side_effect=[None]): assert ansiblegate.__virtual__() == ( False, "The 'ansible' binary was not found.", ) with subtests.test("missing ansible-doc binary"): with patch( "salt.utils.path.which", side_effect=["/path/to/ansible", None], ): assert ansiblegate.__virtual__() == ( False, "The 'ansible-doc' binary was not found.", ) with subtests.test("missing ansible-playbook binary"): with patch( "salt.utils.path.which", side_effect=["/path/to/ansible", "/path/to/ansible-doc", None], ): assert ansiblegate.__virtual__() == ( False, "The 'ansible-playbook' binary was not found.", ) with subtests.test("Failing to load the ansible modules listing"): with patch( "salt.utils.path.which", side_effect=[ "/path/to/ansible", "/path/to/ansible-doc", "/path/to/ansible-playbook", ], ): with patch("subprocess.run") as proc_run_mock: proc_run_mock.return_value.retcode = 1 proc_run_mock.return_value.stderr = "bar" proc_run_mock.return_value.stdout = "{}" assert ansiblegate.__virtual__() == ( False, "Failed to get the listing of ansible modules:\nbar", )
def test_virtual_function(resolver): """ Test Ansible module __virtual__ when ansible is not installed on the minion. :return: """ with patch("salt.modules.ansiblegate.ansible", None): assert ansible.__virtual__() == "ansible"
def test_virtual_function(self): ''' Test Ansible module __virtual__ when ansible is not installed on the minion. :return: ''' with patch('salt.modules.ansiblegate.ansible', None): assert ansible.__virtual__() == 'ansible'
def test_virtual_function_ansible_is_installed(self): ''' Test Ansible module __virtual__ when ansible is installed on the minion. :return: ''' resolver = MagicMock() resolver.resolve = MagicMock() resolver.resolve.install = MagicMock() with patch('salt.modules.ansiblegate.AnsibleModuleResolver', resolver): assert ansible.__virtual__() == (True, None)