Browse Source

More testing of dynamic config regex/lob

pull/1304/head
Ross McFarland 3 months ago
parent
commit
11406e88e2
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
1 changed files with 87 additions and 4 deletions
  1. +87
    -4
      tests/test_octodns_manager.py

+ 87
- 4
tests/test_octodns_manager.py View File

@ -1489,10 +1489,84 @@ class TestManager(TestCase):
manager._get_sources = MagicMock()
manager._get_sources.return_value = [mock_source]
# won't match anything
config_n = {'foo': 42, 'glob': r'*.nope.com.'}
# match things with .a.
config_a = {'foo': 42, 'glob': r'*.a.com.'}
# match things with .b.
config_b = {'bar': 43, 'glob': r'*.b.com.'}
# will match anything
config_c = {'bar': 43, 'glob': r'*'}
zones = {
'*.nope.com.': config_n,
'*.a.com.': config_a,
'*.b.com.': config_b,
'*': config_c,
}
mock_source.list_zones.return_value = [
# matched by a
'one.a.com.',
# matched by a
'two.a.com.',
# matched by b
'one.b.com.',
# matched by b
'two.b.com.',
# matched by c, catch all
'ignored.com.',
]
got = manager._preprocess_zones(zones, sources=[])
# 4 configs
self.assertEqual(4, manager._get_sources.call_count)
# 1 shared source
self.assertEqual(1, mock_source.list_zones.call_count)
self.assertEqual(
{
'one.a.com.': config_a,
'two.a.com.': config_a,
'one.b.com.': config_b,
'two.b.com.': config_b,
'ignored.com.': config_c,
},
got,
)
# if we define the catch all first it'll take everything and leave
# nothing for the others
zones = {
'*': config_c,
'*.nope.com.': config_n,
'*.a.com.': config_a,
'*.b.com.': config_b,
}
got = manager._preprocess_zones(zones, sources=[])
self.assertEqual(
{
'one.a.com.': config_c,
'two.a.com.': config_c,
'one.b.com.': config_c,
'two.b.com.': config_c,
'ignored.com.': config_c,
},
got,
)
def test_preprocess_zones_regex(self):
# these will be unused
environ['YAML_TMP_DIR'] = '/tmp'
environ['YAML_TMP_DIR2'] = '/tmp'
manager = Manager(get_config_filename('simple.yaml'))
manager._get_sources = MagicMock()
mock_source = MagicMock()
mock_source.id = 'mm'
manager._get_sources = MagicMock()
manager._get_sources.return_value = [mock_source]
# match things with .a.
config_a = {'foo': 42, 'regex': r'\.a\.'}
# match things with .b.
config_b = {'bar': 43, 'regex': r'\.b\.'}
zones = {'*.a.com.': config_a, '*.b.com.': config_b}
mock_source.list_zones.side_effect = [
[
@ -1506,7 +1580,7 @@ class TestManager(TestCase):
got = manager._preprocess_zones(zones, sources=[])
self.assertEqual(2, manager._get_sources.call_count)
self.assertEqual(1, mock_source.list_zones.call_count)
# a will glob match .a.com., b will .b.com., ignored.com. won't match
# a will regex match .a.com., b will .b.com., ignored.com. won't match
# anything
self.assertEqual(
{
@ -1518,7 +1592,7 @@ class TestManager(TestCase):
got,
)
def test_preprocess_zones_regex(self):
def test_preprocess_zones_regex_claimed(self):
# these will be unused
environ['YAML_TMP_DIR'] = '/tmp'
environ['YAML_TMP_DIR2'] = '/tmp'
@ -1532,15 +1606,22 @@ class TestManager(TestCase):
# match things with .a.
config_a = {'foo': 42, 'regex': r'\.a\.'}
# match things with .b.
config_b = {'bar': 43, 'regex': r'\.b\.'}
# match everything
config_b = {'bar': 43, 'regex': r'.*'}
zones = {'*.a.com.': config_a, '*.b.com.': config_b}
mock_source.list_zones.side_effect = [
[
# won't match a b/c no . before the a, will match b
'a.com.',
# will match a, and be claimed
'one.a.com.',
# will match a, and be claimed
'two.a.com.',
# will match b
'one.b.com.',
# will match b
'two.b.com.',
# will match b
'ignored.com.',
]
]
@ -1551,10 +1632,12 @@ class TestManager(TestCase):
# anything
self.assertEqual(
{
'a.com.': config_b,
'one.a.com.': config_a,
'two.a.com.': config_a,
'one.b.com.': config_b,
'two.b.com.': config_b,
'ignored.com.': config_b,
},
got,
)


Loading…
Cancel
Save