mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix mock loader for osx /etc symlinks (#16074)
Fix role based unit tests for osx via mock.patch
This commit is contained in:
parent
c06884eff0
commit
373b23cc24
5 changed files with 21 additions and 0 deletions
|
@ -29,6 +29,8 @@ from ansible.playbook.task import Task
|
||||||
from ansible.playbook.play_context import PlayContext
|
from ansible.playbook.play_context import PlayContext
|
||||||
|
|
||||||
from units.mock.loader import DictDataLoader
|
from units.mock.loader import DictDataLoader
|
||||||
|
from units.mock.path import mock_unfrackpath_noop
|
||||||
|
|
||||||
|
|
||||||
class TestPlayIterator(unittest.TestCase):
|
class TestPlayIterator(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -55,7 +57,10 @@ class TestPlayIterator(unittest.TestCase):
|
||||||
|
|
||||||
new_hs = hs.copy()
|
new_hs = hs.copy()
|
||||||
|
|
||||||
|
|
||||||
|
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||||
def test_play_iterator(self):
|
def test_play_iterator(self):
|
||||||
|
#import epdb; epdb.st()
|
||||||
fake_loader = DictDataLoader({
|
fake_loader = DictDataLoader({
|
||||||
"test_play.yml": """
|
"test_play.yml": """
|
||||||
- hosts: all
|
- hosts: all
|
||||||
|
|
5
test/units/mock/path.py
Normal file
5
test/units/mock/path.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
def mock_unfrackpath_noop(path):
|
||||||
|
''' Do not expand the path '''
|
||||||
|
return path
|
|
@ -28,6 +28,8 @@ from ansible.playbook.play import Play
|
||||||
from ansible.playbook.role import Role
|
from ansible.playbook.role import Role
|
||||||
|
|
||||||
from units.mock.loader import DictDataLoader
|
from units.mock.loader import DictDataLoader
|
||||||
|
from units.mock.path import mock_unfrackpath_noop
|
||||||
|
|
||||||
|
|
||||||
class TestPlay(unittest.TestCase):
|
class TestPlay(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -102,6 +104,7 @@ class TestPlay(unittest.TestCase):
|
||||||
post_tasks=[dict(action='shell echo "hello world"')],
|
post_tasks=[dict(action='shell echo "hello world"')],
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||||
def test_play_with_roles(self):
|
def test_play_with_roles(self):
|
||||||
fake_loader = DictDataLoader({
|
fake_loader = DictDataLoader({
|
||||||
'/etc/ansible/roles/foo/tasks.yml': """
|
'/etc/ansible/roles/foo/tasks.yml': """
|
||||||
|
|
|
@ -29,6 +29,7 @@ from ansible.playbook.role.include import RoleInclude
|
||||||
from ansible.playbook.task import Task
|
from ansible.playbook.task import Task
|
||||||
|
|
||||||
from units.mock.loader import DictDataLoader
|
from units.mock.loader import DictDataLoader
|
||||||
|
from units.mock.path import mock_unfrackpath_noop
|
||||||
|
|
||||||
class TestRole(unittest.TestCase):
|
class TestRole(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ class TestRole(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||||
def test_load_role_with_tasks(self):
|
def test_load_role_with_tasks(self):
|
||||||
|
|
||||||
fake_loader = DictDataLoader({
|
fake_loader = DictDataLoader({
|
||||||
|
@ -56,6 +58,7 @@ class TestRole(unittest.TestCase):
|
||||||
self.assertEqual(len(r._task_blocks), 1)
|
self.assertEqual(len(r._task_blocks), 1)
|
||||||
assert isinstance(r._task_blocks[0], Block)
|
assert isinstance(r._task_blocks[0], Block)
|
||||||
|
|
||||||
|
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||||
def test_load_role_with_handlers(self):
|
def test_load_role_with_handlers(self):
|
||||||
|
|
||||||
fake_loader = DictDataLoader({
|
fake_loader = DictDataLoader({
|
||||||
|
@ -74,6 +77,7 @@ class TestRole(unittest.TestCase):
|
||||||
self.assertEqual(len(r._handler_blocks), 1)
|
self.assertEqual(len(r._handler_blocks), 1)
|
||||||
assert isinstance(r._handler_blocks[0], Block)
|
assert isinstance(r._handler_blocks[0], Block)
|
||||||
|
|
||||||
|
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||||
def test_load_role_with_vars(self):
|
def test_load_role_with_vars(self):
|
||||||
|
|
||||||
fake_loader = DictDataLoader({
|
fake_loader = DictDataLoader({
|
||||||
|
@ -94,6 +98,7 @@ class TestRole(unittest.TestCase):
|
||||||
self.assertEqual(r._default_vars, dict(foo='bar'))
|
self.assertEqual(r._default_vars, dict(foo='bar'))
|
||||||
self.assertEqual(r._role_vars, dict(foo='bam'))
|
self.assertEqual(r._role_vars, dict(foo='bam'))
|
||||||
|
|
||||||
|
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||||
def test_load_role_with_metadata(self):
|
def test_load_role_with_metadata(self):
|
||||||
|
|
||||||
fake_loader = DictDataLoader({
|
fake_loader = DictDataLoader({
|
||||||
|
@ -161,6 +166,7 @@ class TestRole(unittest.TestCase):
|
||||||
i = RoleInclude.load('recursive1_metadata', play=mock_play, loader=fake_loader)
|
i = RoleInclude.load('recursive1_metadata', play=mock_play, loader=fake_loader)
|
||||||
self.assertRaises(AnsibleError, Role.load, i, play=mock_play)
|
self.assertRaises(AnsibleError, Role.load, i, play=mock_play)
|
||||||
|
|
||||||
|
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||||
def test_load_role_complex(self):
|
def test_load_role_complex(self):
|
||||||
|
|
||||||
# FIXME: add tests for the more complex uses of
|
# FIXME: add tests for the more complex uses of
|
||||||
|
|
|
@ -29,6 +29,7 @@ from ansible.playbook.play import Play
|
||||||
from ansible.vars import VariableManager
|
from ansible.vars import VariableManager
|
||||||
|
|
||||||
from units.mock.loader import DictDataLoader
|
from units.mock.loader import DictDataLoader
|
||||||
|
from units.mock.path import mock_unfrackpath_noop
|
||||||
|
|
||||||
class TestVariableManager(unittest.TestCase):
|
class TestVariableManager(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -181,6 +182,7 @@ class TestVariableManager(unittest.TestCase):
|
||||||
self.assertEqual(v.get_vars(loader=fake_loader, task=mock_task, use_cache=False).get("foo"), "bar")
|
self.assertEqual(v.get_vars(loader=fake_loader, task=mock_task, use_cache=False).get("foo"), "bar")
|
||||||
|
|
||||||
@patch.object(Inventory, 'basedir')
|
@patch.object(Inventory, 'basedir')
|
||||||
|
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||||
def test_variable_manager_precedence(self, mock_basedir):
|
def test_variable_manager_precedence(self, mock_basedir):
|
||||||
'''
|
'''
|
||||||
Tests complex variations and combinations of get_vars() with different
|
Tests complex variations and combinations of get_vars() with different
|
||||||
|
|
Loading…
Reference in a new issue