mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Services have names
This commit is contained in:
parent
83a086b865
commit
ffdebb84bb
@ -1,5 +1,12 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class Service(object):
|
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.client = client
|
||||||
self.image = image
|
self.image = image
|
||||||
self.command = command
|
self.command = command
|
||||||
|
@ -3,7 +3,24 @@ from docker import Client
|
|||||||
from plum import Service
|
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):
|
def setUp(self):
|
||||||
self.client = Client('http://127.0.0.1:4243')
|
self.client = Client('http://127.0.0.1:4243')
|
||||||
self.client.pull('ubuntu')
|
self.client.pull('ubuntu')
|
||||||
@ -13,6 +30,7 @@ class ServiceTestCase(TestCase):
|
|||||||
self.client.remove_container(c['Id'])
|
self.client.remove_container(c['Id'])
|
||||||
|
|
||||||
self.service = Service(
|
self.service = Service(
|
||||||
|
name="test",
|
||||||
client=self.client,
|
client=self.client,
|
||||||
image="ubuntu",
|
image="ubuntu",
|
||||||
command=["/bin/sleep", "300"],
|
command=["/bin/sleep", "300"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user