Browse Source

Merge pull request #1857 from mnowster/mem-limit-validation

memory values can be strings or numbers
Aanand Prasad 10 years ago
parent
commit
7d5e26bd37
2 changed files with 22 additions and 2 deletions
  1. 12 2
      compose/config/schema.json
  2. 10 0
      tests/unit/config_test.py

+ 12 - 2
compose/config/schema.json

@@ -68,8 +68,18 @@
         },
 
         "mac_address": {"type": "string"},
-        "mem_limit": {"type": "number"},
-        "memswap_limit": {"type": "number"},
+        "mem_limit": {
+          "oneOf": [
+            {"type": "number"},
+            {"type": "string"}
+          ]
+        },
+        "memswap_limit": {
+          "oneOf": [
+            {"type": "number"},
+            {"type": "string"}
+          ]
+        },
         "name": {"type": "string"},
         "net": {"type": "string"},
         "pid": {"type": "string"},

+ 10 - 0
tests/unit/config_test.py

@@ -533,6 +533,16 @@ class MemoryOptionsTest(unittest.TestCase):
         )
         self.assertEqual(service_dict[0]['memswap_limit'], 2000000)
 
+    def test_memswap_can_be_a_string(self):
+        service_dict = config.load(
+            config.ConfigDetails(
+                {'foo': {'image': 'busybox', 'mem_limit': "1G", 'memswap_limit': "512M"}},
+                'tests/fixtures/extends',
+                'common.yml'
+            )
+        )
+        self.assertEqual(service_dict[0]['memswap_limit'], "512M")
+
 
 class EnvTest(unittest.TestCase):
     def test_parse_environment_as_list(self):