mirror of https://github.com/docker/compose.git
Services have names
This commit is contained in:
parent
83a086b865
commit
ffdebb84bb
|
@ -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
|
||||
|
|
|
@ -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"],
|
||||
|
|
Loading…
Reference in New Issue