mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Feature/test inventory (#30707)
* [test] move inventory test to right path * [feat] add unit test for yaml inventory plugin
This commit is contained in:
parent
d0c003ab0f
commit
db70eeb913
3 changed files with 20 additions and 0 deletions
|
@ -20,10 +20,14 @@ from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import string
|
import string
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
from ansible import constants as C
|
||||||
|
from ansible.compat.tests import mock
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text
|
||||||
|
from units.mock.path import mock_unfrackpath_noop
|
||||||
|
|
||||||
from ansible.inventory.manager import InventoryManager, split_host_pattern
|
from ansible.inventory.manager import InventoryManager, split_host_pattern
|
||||||
|
|
||||||
|
@ -156,6 +160,22 @@ class IniInventory(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.assertIsInstance(variables['var%s' % i], type(values[i]))
|
self.assertIsInstance(variables['var%s' % i], type(values[i]))
|
||||||
|
|
||||||
|
@mock.patch('ansible.inventory.manager.unfrackpath', mock_unfrackpath_noop)
|
||||||
|
@mock.patch('os.path.exists', lambda x: True)
|
||||||
|
@mock.patch('os.access', lambda x, y: True)
|
||||||
|
def test_yaml_inventory(self, filename="test.yaml"):
|
||||||
|
inventory_content = {filename: textwrap.dedent("""\
|
||||||
|
---
|
||||||
|
all:
|
||||||
|
hosts:
|
||||||
|
test1
|
||||||
|
test2
|
||||||
|
""")}
|
||||||
|
C.INVENTORY_ENABLED = ['yaml']
|
||||||
|
fake_loader = DictDataLoader(inventory_content)
|
||||||
|
im = InventoryManager(loader=fake_loader, sources=filename)
|
||||||
|
self.assertTrue(im._inventory.hosts)
|
||||||
|
|
||||||
def _get_inventory(self, inventory_content):
|
def _get_inventory(self, inventory_content):
|
||||||
|
|
||||||
fake_loader = DictDataLoader({__file__: inventory_content})
|
fake_loader = DictDataLoader({__file__: inventory_content})
|
Loading…
Reference in a new issue