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

Adding environment variable record injection

Per the discussion on https://github.com/github/octodns/issues/583
here is a work in progress of environment variable injection for
discussion.
This commit is contained in:
Phelps Williams
2020-07-15 18:17:33 -07:00
parent 2e8691e77f
commit 4d006e94a2
2 changed files with 139 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
from six import text_type
from unittest import TestCase
from unittest.mock import patch
from octodns.source.envvar import EnvVarSource
from octodns.source.envvar import EnvironmentVariableNotFoundException
from octodns.zone import Zone
class TestEnvVarSource(TestCase):
def test_read_variable(self):
envvar = 'OCTODNS_TEST_ENVIRONMENT_VARIABLE'
source = EnvVarSource('testid', envvar, 'recordname', ttl=120)
with self.assertRaises(EnvironmentVariableNotFoundException) as ctx:
source._read_variable()
msg = 'Unknown environment variable {}'.format(envvar)
self.assertEquals(msg, text_type(ctx.exception))
with patch.dict('os.environ', {envvar: 'testvalue'}):
source._read_variable()
self.assertEquals(source.value, 'testvalue')
def test_populate(self):
envvar = 'TEST_VAR'
value = 'somevalue'
record = 'testrecord'
source = EnvVarSource('testid', envvar, record)
zone = Zone('unit.tests.', [])
with patch.dict('os.environ', {envvar: value}):
source.populate(zone)
# TODO: Validate zone and record