mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00: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:
@@ -20,10 +20,14 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import string
|
||||
import textwrap
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.compat.tests import mock
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.module_utils.six import string_types
|
||||
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
|
||||
|
||||
@@ -156,6 +160,22 @@ class IniInventory(unittest.TestCase):
|
||||
else:
|
||||
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):
|
||||
|
||||
fake_loader = DictDataLoader({__file__: inventory_content})
|
||||
Reference in New Issue
Block a user