mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Fix mock loader for osx /etc symlinks (#16074)
Fix role based unit tests for osx via mock.patch
This commit is contained in:
@@ -28,6 +28,8 @@ from ansible.playbook.play import Play
|
||||
from ansible.playbook.role import Role
|
||||
|
||||
from units.mock.loader import DictDataLoader
|
||||
from units.mock.path import mock_unfrackpath_noop
|
||||
|
||||
|
||||
class TestPlay(unittest.TestCase):
|
||||
|
||||
@@ -102,6 +104,7 @@ class TestPlay(unittest.TestCase):
|
||||
post_tasks=[dict(action='shell echo "hello world"')],
|
||||
))
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_play_with_roles(self):
|
||||
fake_loader = DictDataLoader({
|
||||
'/etc/ansible/roles/foo/tasks.yml': """
|
||||
|
||||
@@ -29,6 +29,7 @@ from ansible.playbook.role.include import RoleInclude
|
||||
from ansible.playbook.task import Task
|
||||
|
||||
from units.mock.loader import DictDataLoader
|
||||
from units.mock.path import mock_unfrackpath_noop
|
||||
|
||||
class TestRole(unittest.TestCase):
|
||||
|
||||
@@ -38,6 +39,7 @@ class TestRole(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_load_role_with_tasks(self):
|
||||
|
||||
fake_loader = DictDataLoader({
|
||||
@@ -56,6 +58,7 @@ class TestRole(unittest.TestCase):
|
||||
self.assertEqual(len(r._task_blocks), 1)
|
||||
assert isinstance(r._task_blocks[0], Block)
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_load_role_with_handlers(self):
|
||||
|
||||
fake_loader = DictDataLoader({
|
||||
@@ -74,6 +77,7 @@ class TestRole(unittest.TestCase):
|
||||
self.assertEqual(len(r._handler_blocks), 1)
|
||||
assert isinstance(r._handler_blocks[0], Block)
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_load_role_with_vars(self):
|
||||
|
||||
fake_loader = DictDataLoader({
|
||||
@@ -94,6 +98,7 @@ class TestRole(unittest.TestCase):
|
||||
self.assertEqual(r._default_vars, dict(foo='bar'))
|
||||
self.assertEqual(r._role_vars, dict(foo='bam'))
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_load_role_with_metadata(self):
|
||||
|
||||
fake_loader = DictDataLoader({
|
||||
@@ -161,6 +166,7 @@ class TestRole(unittest.TestCase):
|
||||
i = RoleInclude.load('recursive1_metadata', play=mock_play, loader=fake_loader)
|
||||
self.assertRaises(AnsibleError, Role.load, i, play=mock_play)
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_load_role_complex(self):
|
||||
|
||||
# FIXME: add tests for the more complex uses of
|
||||
|
||||
Reference in New Issue
Block a user