summaryrefslogtreecommitdiff
path: root/oslo_config/tests/test_sources.py
diff options
context:
space:
mode:
Diffstat (limited to 'oslo_config/tests/test_sources.py')
-rw-r--r--oslo_config/tests/test_sources.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/oslo_config/tests/test_sources.py b/oslo_config/tests/test_sources.py
index 656f61e..2da73da 100644
--- a/oslo_config/tests/test_sources.py
+++ b/oslo_config/tests/test_sources.py
@@ -15,6 +15,7 @@ import os
from oslotest import base
from requests import HTTPError
import requests_mock
+import testtools
from oslo_config import _list_opts
from oslo_config import cfg
@@ -120,10 +121,13 @@ class TestEnvironmentConfigurationSource(base.BaseTestCase):
self.conf = cfg.ConfigOpts()
self.conf_fixture = self.useFixture(fixture.Config(self.conf))
self.conf.register_opt(cfg.StrOpt('bar'), 'foo')
+ self.conf.register_opt(cfg.StrOpt('baz', regex='^[a-z].*$'), 'foo')
def cleanup():
- if 'OS_FOO__BAR' in os.environ:
- del os.environ['OS_FOO__BAR']
+ for env in ('OS_FOO__BAR', 'OS_FOO__BAZ'):
+ if env in os.environ:
+ del os.environ[env]
+
self.addCleanup(cleanup)
def test_simple_environment_get(self):
@@ -171,6 +175,14 @@ class TestEnvironmentConfigurationSource(base.BaseTestCase):
self.conf(args=[], use_env=True)
self.assertEqual(env_value, self.conf['foo']['bar'])
+ def test_invalid_env(self):
+ self.conf(args=[])
+ env_value = 'ABC'
+ os.environ['OS_FOO__BAZ'] = env_value
+
+ with testtools.ExpectedException(cfg.ConfigSourceValueError):
+ self.conf['foo']['baz']
+
def make_uri(name):
return "https://oslo.config/{}.conf".format(name)