[CORD-1360] Using new Config in synchronizers
Change-Id: Iaa7c3394971286f4823a906fc184b0b83ad7ebbd
diff --git a/lib/xos-config/tests/config_test.py b/lib/xos-config/tests/config_test.py
index a3e57db..b98b817 100644
--- a/lib/xos-config/tests/config_test.py
+++ b/lib/xos-config/tests/config_test.py
@@ -9,6 +9,8 @@
invalid_format = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/confs/invalid_format.yaml")
sample_conf = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/confs/sample_conf.yaml")
+small_schema = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/schemas/small_schema.yaml")
+
services_list = {
"xos-ws": [],
"xos-db": [],
@@ -81,13 +83,34 @@
def test_env_override(self):
"""
- [XOS-Config] the XOS-CONFIG environment variable should override the config_file
+ [XOS-Config] the XOS_CONFIG_FILE environment variable should override the config_file
"""
- os.environ["XOS-CONFIG"] = "env.yaml"
+ os.environ["XOS_CONFIG_FILE"] = "env.yaml"
with self.assertRaises(Exception) as e:
Config.init("missing_conf")
self.assertEqual(e.exception.message, "[XOS-Config] Config file not found at: env.yaml")
- del os.environ["XOS-CONFIG"]
+ del os.environ["XOS_CONFIG_FILE"]
+
+ def test_schema_override(self):
+ """
+ [XOS-Config] the XOS_CONFIG_SCHEMA environment variable should override the config_schema
+ """
+ os.environ["XOS_CONFIG_SCHEMA"] = "env-schema.yaml"
+ with self.assertRaises(Exception) as e:
+ Config.init(basic_conf)
+ self.assertRegexpMatches(e.exception.message, '\[XOS\-Config\] Config schema not found at: (.+)env-schema\.yaml')
+ # self.assertEqual(e.exception.message, "[XOS-Config] Config schema not found at: env-schema.yaml")
+ del os.environ["XOS_CONFIG_SCHEMA"]
+
+ def test_schema_override_usage(self):
+ """
+ [XOS-Config] the XOS_CONFIG_SCHEMA should be used to validate a config
+ """
+ os.environ["XOS_CONFIG_SCHEMA"] = small_schema
+ with self.assertRaises(Exception) as e:
+ Config.init(basic_conf)
+ self.assertEqual(e.exception.message, "[XOS-Config] The config format is wrong: Schema validation failed:\n - Key 'database' was not defined. Path: ''.")
+ del os.environ["XOS_CONFIG_SCHEMA"]
def test_get_cli_param(self):
"""
@@ -99,13 +122,15 @@
def test_get_default_val_for_missing_param(self):
"""
- [XOS-Config] Should raise reading a missing param
+ [XOS-Config] Should get the default value if nothing is specified
"""
Config.init(basic_conf)
log = Config.get("logging")
self.assertEqual(log, {
"level": "info",
- "channels": ["file", "console"]
+ "channels": ["file", "console"],
+ "logstash_hostport": "cordloghost:5617",
+ "file": "/var/log/xos.log",
})
def _test_get_missing_param(self):
@@ -113,9 +138,8 @@
[XOS-Config] Should raise reading a missing param
"""
Config.init(sample_conf)
- with self.assertRaises(Exception) as e:
- Config.get("foo")
- self.assertEqual(e.exception.message, "[XOS-Config] Config does not have a value (or a default) parameter foo")
+ res = Config.get("foo")
+ self.assertEqual(res, None)
def test_get_first_level(self):
"""
@@ -192,4 +216,8 @@
with patch("xosconfig.config.requests.get") as mock_get:
mock_get.return_value.json.return_value = db_service
endpoint = Config.get_service_endpoint("xos-db")
- self.assertEqual(endpoint, "http://172.18.0.4:5432")
\ No newline at end of file
+ self.assertEqual(endpoint, "http://172.18.0.4:5432")
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/lib/xos-config/tests/confs/sample_conf.yaml b/lib/xos-config/tests/confs/sample_conf.yaml
index 4d4c792..b9867ed 100644
--- a/lib/xos-config/tests/confs/sample_conf.yaml
+++ b/lib/xos-config/tests/confs/sample_conf.yaml
@@ -7,4 +7,5 @@
level: info
channels:
- file
- - console
\ No newline at end of file
+ - console
+xos_dir: /opt/xos
\ No newline at end of file
diff --git a/lib/xos-config/tests/schemas/small_schema.yaml b/lib/xos-config/tests/schemas/small_schema.yaml
new file mode 100644
index 0000000..4afbd92
--- /dev/null
+++ b/lib/xos-config/tests/schemas/small_schema.yaml
@@ -0,0 +1,4 @@
+map:
+ name:
+ type: str
+ required: True
\ No newline at end of file