瀏覽代碼

Add a test for invalid field 'name', and fix an existing test for invalid service names.

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin 10 年之前
父節點
當前提交
19b2c41c7e
共有 1 個文件被更改,包括 12 次插入2 次删除
  1. 12 2
      tests/unit/config/config_test.py

+ 12 - 2
tests/unit/config/config_test.py

@@ -77,8 +77,8 @@ class ConfigTest(unittest.TestCase):
             )
 
     def test_config_invalid_service_names(self):
-        with self.assertRaises(ConfigurationError):
-            for invalid_name in ['?not?allowed', ' ', '', '!', '/', '\xe2']:
+        for invalid_name in ['?not?allowed', ' ', '', '!', '/', '\xe2']:
+            with pytest.raises(ConfigurationError):
                 config.load(
                     build_config_details(
                         {invalid_name: {'image': 'busybox'}},
@@ -87,6 +87,16 @@ class ConfigTest(unittest.TestCase):
                     )
                 )
 
+    def test_load_with_invalid_field_name(self):
+        config_details = build_config_details(
+            {'web': {'image': 'busybox', 'name': 'bogus'}},
+            'working_dir',
+            'filename.yml')
+        with pytest.raises(ConfigurationError) as exc:
+            config.load(config_details)
+        error_msg = "Unsupported config option for 'web' service: 'name'"
+        assert error_msg in exc.exconly()
+
     def test_config_integer_service_name_raise_validation_error(self):
         expected_error_msg = "Service name: 1 needs to be a string, eg '1'"
         with self.assertRaisesRegexp(ConfigurationError, expected_error_msg):