mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Update role unit tests for changes made to require a play during loading
This commit is contained in:
parent
f8ddf2eb04
commit
bbe8f48a46
1 changed files with 23 additions and 8 deletions
|
@ -46,8 +46,11 @@ class TestRole(unittest.TestCase):
|
|||
""",
|
||||
})
|
||||
|
||||
mock_play = MagicMock()
|
||||
mock_play.ROLE_CACHE = {}
|
||||
|
||||
i = RoleInclude.load('foo_tasks', loader=fake_loader)
|
||||
r = Role.load(i)
|
||||
r = Role.load(i, play=mock_play)
|
||||
|
||||
self.assertEqual(str(r), 'foo_tasks')
|
||||
self.assertEqual(len(r._task_blocks), 1)
|
||||
|
@ -62,8 +65,11 @@ class TestRole(unittest.TestCase):
|
|||
""",
|
||||
})
|
||||
|
||||
mock_play = MagicMock()
|
||||
mock_play.ROLE_CACHE = {}
|
||||
|
||||
i = RoleInclude.load('foo_handlers', loader=fake_loader)
|
||||
r = Role.load(i)
|
||||
r = Role.load(i, play=mock_play)
|
||||
|
||||
self.assertEqual(len(r._handler_blocks), 1)
|
||||
assert isinstance(r._handler_blocks[0], Block)
|
||||
|
@ -79,8 +85,11 @@ class TestRole(unittest.TestCase):
|
|||
""",
|
||||
})
|
||||
|
||||
mock_play = MagicMock()
|
||||
mock_play.ROLE_CACHE = {}
|
||||
|
||||
i = RoleInclude.load('foo_vars', loader=fake_loader)
|
||||
r = Role.load(i)
|
||||
r = Role.load(i, play=mock_play)
|
||||
|
||||
self.assertEqual(r._default_vars, dict(foo='bar'))
|
||||
self.assertEqual(r._role_vars, dict(foo='bam'))
|
||||
|
@ -122,8 +131,11 @@ class TestRole(unittest.TestCase):
|
|||
""",
|
||||
})
|
||||
|
||||
mock_play = MagicMock()
|
||||
mock_play.ROLE_CACHE = {}
|
||||
|
||||
i = RoleInclude.load('foo_metadata', loader=fake_loader)
|
||||
r = Role.load(i)
|
||||
r = Role.load(i, play=mock_play)
|
||||
|
||||
role_deps = r.get_direct_dependencies()
|
||||
|
||||
|
@ -141,13 +153,13 @@ class TestRole(unittest.TestCase):
|
|||
self.assertEqual(all_deps[2].get_name(), 'bar_metadata')
|
||||
|
||||
i = RoleInclude.load('bad1_metadata', loader=fake_loader)
|
||||
self.assertRaises(AnsibleParserError, Role.load, i)
|
||||
self.assertRaises(AnsibleParserError, Role.load, i, play=mock_play)
|
||||
|
||||
i = RoleInclude.load('bad2_metadata', loader=fake_loader)
|
||||
self.assertRaises(AnsibleParserError, Role.load, i)
|
||||
self.assertRaises(AnsibleParserError, Role.load, i, play=mock_play)
|
||||
|
||||
i = RoleInclude.load('recursive1_metadata', loader=fake_loader)
|
||||
self.assertRaises(AnsibleError, Role.load, i)
|
||||
self.assertRaises(AnsibleError, Role.load, i, play=mock_play)
|
||||
|
||||
def test_load_role_complex(self):
|
||||
|
||||
|
@ -160,8 +172,11 @@ class TestRole(unittest.TestCase):
|
|||
""",
|
||||
})
|
||||
|
||||
mock_play = MagicMock()
|
||||
mock_play.ROLE_CACHE = {}
|
||||
|
||||
i = RoleInclude.load(dict(role='foo_complex'), loader=fake_loader)
|
||||
r = Role.load(i)
|
||||
r = Role.load(i, play=mock_play)
|
||||
|
||||
self.assertEqual(r.get_name(), "foo_complex")
|
||||
|
||||
|
|
Loading…
Reference in a new issue