1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge branch 'tests' of https://github.com/amenonsen/ansible into amenonsen-tests

This commit is contained in:
James Cammarata 2015-09-30 08:06:52 -04:00
commit 6339bf8a82
2 changed files with 31 additions and 0 deletions

View file

@ -26,6 +26,7 @@ from ansible.compat.tests.mock import patch, MagicMock
from ansible.errors import AnsibleError, AnsibleParserError from ansible.errors import AnsibleError, AnsibleParserError
from ansible.inventory import Inventory from ansible.inventory import Inventory
from ansible.inventory.expand_hosts import expand_hostname_range
from ansible.vars import VariableManager from ansible.vars import VariableManager
from units.mock.loader import DictDataLoader from units.mock.loader import DictDataLoader
@ -71,6 +72,16 @@ class TestInventory(unittest.TestCase):
'a[1:]': [('a', (1, -1)), list(string.ascii_letters[1:])], 'a[1:]': [('a', (1, -1)), list(string.ascii_letters[1:])],
} }
ranges_to_expand = {
'a[1:2]': ['a1', 'a2'],
'a[1:10:2]': ['a1', 'a3', 'a5', 'a7', 'a9'],
'a[a:b]': ['aa', 'ab'],
'a[a:i:3]': ['aa', 'ad', 'ag'],
'a[a:b][c:d]': ['aac', 'aad', 'abc', 'abd'],
'a[0:1][2:3]': ['a02', 'a03', 'a12', 'a13'],
'a[a:b][2:3]': ['aa2', 'aa3', 'ab2', 'ab3'],
}
def setUp(self): def setUp(self):
v = VariableManager() v = VariableManager()
fake_loader = DictDataLoader({}) fake_loader = DictDataLoader({})
@ -98,3 +109,9 @@ class TestInventory(unittest.TestCase):
r[0][1] r[0][1]
) )
) )
def test_expand_hostname_range(self):
for e in self.ranges_to_expand:
r = self.ranges_to_expand[e]
self.assertEqual(r, expand_hostname_range(e))

View file

@ -17,6 +17,20 @@ class TestParseAddress(unittest.TestCase):
'[::1]:442': ['::1', 442], '[::1]:442': ['::1', 442],
'abcd:ef98:7654:3210:abcd:ef98:7654:3210': ['abcd:ef98:7654:3210:abcd:ef98:7654:3210', None], 'abcd:ef98:7654:3210:abcd:ef98:7654:3210': ['abcd:ef98:7654:3210:abcd:ef98:7654:3210', None],
'[abcd:ef98:7654:3210:abcd:ef98:7654:3210]:42': ['abcd:ef98:7654:3210:abcd:ef98:7654:3210', 42], '[abcd:ef98:7654:3210:abcd:ef98:7654:3210]:42': ['abcd:ef98:7654:3210:abcd:ef98:7654:3210', 42],
'1234:5678:9abc:def0:1234:5678:9abc:def0': ['1234:5678:9abc:def0:1234:5678:9abc:def0', None],
'1234::9abc:def0:1234:5678:9abc:def0': ['1234::9abc:def0:1234:5678:9abc:def0', None],
'1234:5678::def0:1234:5678:9abc:def0': ['1234:5678::def0:1234:5678:9abc:def0', None],
'1234:5678:9abc::1234:5678:9abc:def0': ['1234:5678:9abc::1234:5678:9abc:def0', None],
'1234:5678:9abc:def0::5678:9abc:def0': ['1234:5678:9abc:def0::5678:9abc:def0', None],
'1234:5678:9abc:def0:1234::9abc:def0': ['1234:5678:9abc:def0:1234::9abc:def0', None],
'1234:5678:9abc:def0:1234:5678::def0': ['1234:5678:9abc:def0:1234:5678::def0', None],
'1234:5678:9abc:def0:1234:5678::': ['1234:5678:9abc:def0:1234:5678::', None],
'::9abc:def0:1234:5678:9abc:def0': ['::9abc:def0:1234:5678:9abc:def0', None],
'0:0:0:0:0:ffff:1.2.3.4': ['0:0:0:0:0:ffff:1.2.3.4', None],
'0:0:0:0:0:0:1.2.3.4': ['0:0:0:0:0:0:1.2.3.4', None],
'::ffff:1.2.3.4': ['::ffff:1.2.3.4', None],
'::1.2.3.4': ['::1.2.3.4', None],
'1234::': ['1234::', None],
# Hostnames # Hostnames
'some-host': ['some-host', None], 'some-host': ['some-host', None],