1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Merge remote-tracking branch 'origin/main' into yaml-provider-static

This commit is contained in:
Ross McFarland
2023-08-31 10:52:12 -07:00
7 changed files with 165 additions and 31 deletions

View File

@@ -260,10 +260,13 @@ xn--dj-kia8a:
zone = Zone('unit.tests.', ['sub'])
with self.assertRaises(SubzoneRecordException) as ctx:
source.populate(zone)
self.assertEqual(
'Record www.sub.unit.tests. is under a managed subzone',
str(ctx.exception),
msg = str(ctx.exception)
self.assertTrue(
msg.startswith(
'Record www.sub.unit.tests. is under a managed subzone'
)
)
self.assertTrue(msg.endswith('unit.tests.yaml, line 201, column 3'))
def test_SUPPORTS(self):
source = YamlProvider('test', join(dirname(__file__), 'config'))
@@ -694,10 +697,13 @@ class TestSplitYamlProvider(TestCase):
zone = Zone('unit.tests.', ['sub'])
with self.assertRaises(SubzoneRecordException) as ctx:
source.populate(zone)
self.assertEqual(
'Record www.sub.unit.tests. is under a managed subzone',
str(ctx.exception),
msg = str(ctx.exception)
self.assertTrue(
msg.startswith(
'Record www.sub.unit.tests. is under a managed subzone'
)
)
self.assertTrue(msg.endswith('www.sub.yaml, line 3, column 3'))
def test_copy(self):
# going to put some sentinal values in here to ensure, these aren't

View File

@@ -628,3 +628,13 @@ class TestRecordValidation(TestCase):
ContextDict({'ttl': 42, 'value': '1.2.3.4'}, context='needle'),
)
self.assertTrue('needle' in str(ctx.exception))
def test_context_copied_to_record(self):
record = Record.new(
self.zone,
'www',
ContextDict(
{'ttl': 42, 'type': 'A', 'value': '1.2.3.4'}, context='needle'
),
)
self.assertEqual('needle', record.context)

View File

@@ -6,6 +6,7 @@ from unittest import TestCase
from helpers import SimpleProvider
from octodns.context import ContextDict
from octodns.idna import idna_encode
from octodns.record import (
AaaaRecord,
@@ -106,6 +107,62 @@ class TestZone(TestCase):
zone.add_record(b)
self.assertEqual(zone.records, set([a, b]))
def test_duplicate_context_handling(self):
zone = Zone('unit.tests.', [])
# these will be ==, but one has context and the other doesn't
no_context = ARecord(zone, 'a', {'ttl': 42, 'value': '1.1.1.1'})
has_context = ARecord(
zone, 'a', {'ttl': 42, 'value': '1.1.1.1'}, context='hello world'
)
# both have context
zone.add_record(has_context)
with self.assertRaises(DuplicateRecordException) as ctx:
zone.add_record(has_context)
self.assertEqual(has_context, ctx.exception.existing)
self.assertEqual(has_context, ctx.exception.new)
zone.remove_record(has_context)
self.assertEqual(
[
'Duplicate record a.unit.tests., type A',
' existing: hello world',
' new: hello world',
],
str(ctx.exception).split('\n'),
)
# new has context
zone.add_record(no_context)
with self.assertRaises(DuplicateRecordException) as ctx:
zone.add_record(has_context)
self.assertEqual(no_context, ctx.exception.existing)
self.assertEqual(has_context, ctx.exception.new)
zone.remove_record(no_context)
self.assertEqual(
[
'Duplicate record a.unit.tests., type A',
' existing: [UNKNOWN]',
' new: hello world',
],
str(ctx.exception).split('\n'),
)
# existing has context
zone.add_record(has_context)
with self.assertRaises(DuplicateRecordException) as ctx:
zone.add_record(no_context)
self.assertEqual(has_context, ctx.exception.existing)
self.assertEqual(no_context, ctx.exception.new)
self.assertEqual(
[
'Duplicate record a.unit.tests., type A',
' existing: hello world',
' new: [UNKNOWN]',
],
str(ctx.exception).split('\n'),
)
def test_changes(self):
before = Zone('unit.tests.', [])
a = ARecord(before, 'a', {'ttl': 42, 'value': '1.1.1.1'})
@@ -242,9 +299,11 @@ class TestZone(TestCase):
'sub',
{'ttl': 3600, 'type': 'A', 'values': ['1.2.3.4', '2.3.4.5']},
)
record.context = 'added context'
with self.assertRaises(SubzoneRecordException) as ctx:
zone.add_record(record)
self.assertTrue('not of type NS', str(ctx.exception))
self.assertTrue(', added context' in str(ctx.exception))
# Can add it w/lenient
zone.add_record(record, lenient=True)
self.assertEqual(set([record]), zone.records)
@@ -328,11 +387,13 @@ class TestZone(TestCase):
cname = Record.new(
zone, 'www', {'ttl': 60, 'type': 'CNAME', 'value': 'foo.bar.com.'}
)
cname.context = 'has some context'
# add cname to a
zone.add_record(a)
with self.assertRaises(InvalidNodeException):
with self.assertRaises(InvalidNodeException) as ctx:
zone.add_record(cname)
self.assertTrue(', has some context' in str(ctx.exception))
self.assertEqual(set([a]), zone.records)
zone.add_record(cname, lenient=True)
self.assertEqual(set([a, cname]), zone.records)
@@ -501,6 +562,22 @@ class TestZone(TestCase):
# Doesn't the second
self.assertFalse(copy.hydrate())
def test_copy_context(self):
zone = Zone('unit.tests.', [])
no_context = Record.new(
zone, 'a', {'ttl': 42, 'type': 'A', 'value': '1.1.1.1'}
)
self.assertFalse(no_context.context)
self.assertFalse(no_context.copy().context)
data = ContextDict(
{'ttl': 42, 'type': 'A', 'value': '1.1.1.1'}, context='hello world'
)
has_context = Record.new(zone, 'a', data)
self.assertTrue(has_context.context)
self.assertTrue(has_context.copy().context)
def test_root_ns(self):
zone = Zone('unit.tests.', [])