Преглед на файлове

Merge pull request #2975 from dnephin/fix_crash_on_none_in_config

Fix validation message when there are multiple nested oneOf validations.
Daniel Nephin преди 9 години
родител
ревизия
d5514965d5
променени са 2 файла, в които са добавени 25 реда и са изтрити 0 реда
  1. 4 0
      compose/config/validation.py
  2. 21 0
      tests/unit/config/config_test.py

+ 4 - 0
compose/config/validation.py

@@ -332,6 +332,10 @@ def _parse_oneof_validator(error):
     types = []
     for context in error.context:
 
+        if context.validator == 'oneOf':
+            _, error_msg = _parse_oneof_validator(context)
+            return path_string(context.path), error_msg
+
         if context.validator == 'required':
             return (None, context.message)
 

+ 21 - 0
tests/unit/config/config_test.py

@@ -394,6 +394,27 @@ class ConfigTest(unittest.TestCase):
             config.load(config_details)
         assert "service 'web' must be a mapping not a string." in exc.exconly()
 
+    def test_load_with_empty_build_args(self):
+        config_details = build_config_details(
+            {
+                'version': '2',
+                'services': {
+                    'web': {
+                        'build': {
+                            'context': '.',
+                            'args': None,
+                        },
+                    },
+                },
+            }
+        )
+        with pytest.raises(ConfigurationError) as exc:
+            config.load(config_details)
+        assert (
+            "services.web.build.args contains an invalid type, it should be an "
+            "array, or an object" in exc.exconly()
+        )
+
     def test_config_integer_service_name_raise_validation_error(self):
         with pytest.raises(ConfigurationError) as excinfo:
             config.load(