Browse Source

Update doc wording for ulimits.

and move tests to the correct module

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin 10 years ago
parent
commit
7365a398b3
3 changed files with 45 additions and 33 deletions
  1. 3 2
      docs/compose-file.md
  2. 0 31
      tests/integration/service_test.py
  3. 42 0
      tests/unit/service_test.py

+ 3 - 2
docs/compose-file.md

@@ -335,8 +335,9 @@ Override the default labeling scheme for each container.
 
 ### ulimits
 
-Override the default ulimits for a container. You can either use a number
-to set the hard and soft limits, or specify them in a dictionary.
+Override the default ulimits for a container. You can either specify a single
+limit as an integer or soft/hard limits as a mapping.
+
 
       ulimits:
         nproc: 65535

+ 0 - 31
tests/integration/service_test.py

@@ -22,7 +22,6 @@ from compose.const import LABEL_SERVICE
 from compose.const import LABEL_VERSION
 from compose.container import Container
 from compose.service import build_extra_hosts
-from compose.service import build_ulimits
 from compose.service import ConfigError
 from compose.service import ConvergencePlan
 from compose.service import ConvergenceStrategy
@@ -165,36 +164,6 @@ class ServiceTest(DockerClientTestCase):
             {'www.example.com': '192.168.0.17',
              'api.example.com': '192.168.0.18'})
 
-    def sort_dicts_by_name(self, dictionary_list):
-        return sorted(dictionary_list, key=lambda k: k['name'])
-
-    def test_build_ulimits_with_invalid_options(self):
-        self.assertRaises(ConfigError, lambda: build_ulimits({'nofile': {'soft': 10000, 'hard': 10}}))
-
-    def test_build_ulimits_with_integers(self):
-        self.assertEqual(build_ulimits(
-            {'nofile': {'soft': 10000, 'hard': 20000}}),
-            [{'name': 'nofile', 'soft': 10000, 'hard': 20000}])
-        self.assertEqual(self.sort_dicts_by_name(build_ulimits(
-            {'nofile': {'soft': 10000, 'hard': 20000}, 'nproc': {'soft': 65535, 'hard': 65535}})),
-            self.sort_dicts_by_name([{'name': 'nofile', 'soft': 10000, 'hard': 20000},
-                                     {'name': 'nproc', 'soft': 65535, 'hard': 65535}]))
-
-    def test_build_ulimits_with_dicts(self):
-        self.assertEqual(build_ulimits(
-            {'nofile': 20000}),
-            [{'name': 'nofile', 'soft': 20000, 'hard': 20000}])
-        self.assertEqual(self.sort_dicts_by_name(build_ulimits(
-            {'nofile': 20000, 'nproc': 65535})),
-            self.sort_dicts_by_name([{'name': 'nofile', 'soft': 20000, 'hard': 20000},
-                                     {'name': 'nproc', 'soft': 65535, 'hard': 65535}]))
-
-    def test_build_ulimits_with_integers_and_dicts(self):
-        self.assertEqual(self.sort_dicts_by_name(build_ulimits(
-            {'nproc': 65535, 'nofile': {'soft': 10000, 'hard': 20000}})),
-            self.sort_dicts_by_name([{'name': 'nofile', 'soft': 10000, 'hard': 20000},
-                                     {'name': 'nproc', 'soft': 65535, 'hard': 65535}]))
-
     def test_create_container_with_extra_hosts_list(self):
         extra_hosts = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
         service = self.create_service('db', extra_hosts=extra_hosts)

+ 42 - 0
tests/unit/service_test.py

@@ -12,6 +12,7 @@ from compose.const import LABEL_ONE_OFF
 from compose.const import LABEL_PROJECT
 from compose.const import LABEL_SERVICE
 from compose.container import Container
+from compose.service import build_ulimits
 from compose.service import build_volume_binding
 from compose.service import ConfigError
 from compose.service import ContainerNet
@@ -497,6 +498,47 @@ class ServiceTest(unittest.TestCase):
         self.assertEqual(service._get_links(link_to_self=True), [])
 
 
+def sort_by_name(dictionary_list):
+    return sorted(dictionary_list, key=lambda k: k['name'])
+
+
+class BuildUlimitsTestCase(unittest.TestCase):
+
+    def test_build_ulimits_with_dict(self):
+        ulimits = build_ulimits(
+            {
+                'nofile': {'soft': 10000, 'hard': 20000},
+                'nproc': {'soft': 65535, 'hard': 65535}
+            }
+        )
+        expected = [
+            {'name': 'nofile', 'soft': 10000, 'hard': 20000},
+            {'name': 'nproc', 'soft': 65535, 'hard': 65535}
+        ]
+        assert sort_by_name(ulimits) == sort_by_name(expected)
+
+    def test_build_ulimits_with_ints(self):
+        ulimits = build_ulimits({'nofile': 20000, 'nproc': 65535})
+        expected = [
+            {'name': 'nofile', 'soft': 20000, 'hard': 20000},
+            {'name': 'nproc', 'soft': 65535, 'hard': 65535}
+        ]
+        assert sort_by_name(ulimits) == sort_by_name(expected)
+
+    def test_build_ulimits_with_integers_and_dicts(self):
+        ulimits = build_ulimits(
+            {
+                'nproc': 65535,
+                'nofile': {'soft': 10000, 'hard': 20000}
+            }
+        )
+        expected = [
+            {'name': 'nofile', 'soft': 10000, 'hard': 20000},
+            {'name': 'nproc', 'soft': 65535, 'hard': 65535}
+        ]
+        assert sort_by_name(ulimits) == sort_by_name(expected)
+
+
 class NetTestCase(unittest.TestCase):
 
     def test_net(self):