浏览代码

Environment keys can contain empty values

Environment keys that contain no value, get populated with values taken
from the environment not from the build phase but from running the command `up`.

Signed-off-by: Mazz Mosley <[email protected]>
Mazz Mosley 10 年之前
父节点
当前提交
08add665e9
共有 3 个文件被更改,包括 19 次插入2 次删除
  1. 1 1
      compose/config/fields_schema.json
  2. 1 1
      compose/config/validation.py
  3. 17 0
      tests/unit/config/config_test.py

+ 1 - 1
compose/config/fields_schema.json

@@ -41,7 +41,7 @@
               "type": "object",
               "patternProperties": {
                 "^[^-]+$": {
-                  "type": ["string", "number", "boolean"],
+                  "type": ["string", "number", "boolean", "null"],
                   "format": "environment"
                 }
               },

+ 1 - 1
compose/config/validation.py

@@ -143,7 +143,7 @@ def process_errors(errors, service_name=None):
             if len(validator) >= 2:
                 first_type = anglicize_validator(validator[0])
                 last_type = anglicize_validator(validator[-1])
-                types_from_validator = "{}".format(", ".join([first_type] + validator[1:-1]))
+                types_from_validator = ", ".join([first_type] + validator[1:-1])
 
                 msg = "{} or {}".format(
                     types_from_validator,

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

@@ -414,6 +414,23 @@ class InterpolationTest(unittest.TestCase):
         self.assertIn('in service "web"', cm.exception.msg)
         self.assertIn('"${"', cm.exception.msg)
 
+    def test_empty_environment_key_allowed(self):
+        service_dict = config.load(
+            build_config_details(
+                {
+                    'web': {
+                        'build': '.',
+                        'environment': {
+                            'POSTGRES_PASSWORD': ''
+                        },
+                    },
+                },
+                '.',
+                None,
+            )
+        )[0]
+        self.assertEquals(service_dict['environment']['POSTGRES_PASSWORD'], '')
+
 
 class VolumeConfigTest(unittest.TestCase):
     def test_no_binding(self):