소스 검색

Services have names

Aanand Prasad 12 년 전
부모
커밋
ffdebb84bb
2개의 변경된 파일27개의 추가작업 그리고 2개의 파일을 삭제
  1. 8 1
      plum/service.py
  2. 19 1
      plum/tests/service_test.py

+ 8 - 1
plum/service.py

@@ -1,5 +1,12 @@
+import re
+
+
 class Service(object):
-    def __init__(self, client, image, command):
+    def __init__(self, name, client=None, image=None, command=None):
+        if not re.match('^[a-zA-Z0-9_]+$', name):
+            raise ValueError('Invalid name: %s' % name)
+
+        self.name = name
         self.client = client
         self.image = image
         self.command = command

+ 19 - 1
plum/tests/service_test.py

@@ -3,7 +3,24 @@ from docker import Client
 from plum import Service
 
 
-class ServiceTestCase(TestCase):
+class NameTestCase(TestCase):
+    def test_name_validations(self):
+        self.assertRaises(ValueError, lambda: Service(name=''))
+
+        self.assertRaises(ValueError, lambda: Service(name=' '))
+        self.assertRaises(ValueError, lambda: Service(name='/'))
+        self.assertRaises(ValueError, lambda: Service(name='!'))
+        self.assertRaises(ValueError, lambda: Service(name='\xe2'))
+
+        Service('a')
+        Service('foo')
+        Service('foo_bar')
+        Service('__foo_bar__')
+        Service('_')
+        Service('_____')
+
+
+class ScalingTestCase(TestCase):
     def setUp(self):
         self.client = Client('http://127.0.0.1:4243')
         self.client.pull('ubuntu')
@@ -13,6 +30,7 @@ class ServiceTestCase(TestCase):
             self.client.remove_container(c['Id'])
 
         self.service = Service(
+            name="test",
             client=self.client,
             image="ubuntu",
             command=["/bin/sleep", "300"],