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:
34
tests/test_octodns_source_envvar.py
Normal file
34
tests/test_octodns_source_envvar.py
Normal 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
|
Reference in New Issue
Block a user