Do not allow underscores in names

This commit is contained in:
Ben Firshman 2013-12-19 14:47:43 +00:00
parent 9f1d08c54b
commit 6c551a200b
2 changed files with 6 additions and 6 deletions

View File

@ -13,7 +13,7 @@ class BuildError(Exception):
class Service(object):
def __init__(self, name, client=None, links=[], **options):
if not re.match('^[a-zA-Z0-9_]+$', name):
if not re.match('^[a-zA-Z0-9]+$', name):
raise ValueError('Invalid name: %s' % name)
if 'image' in options and 'build' in options:
raise ValueError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name)

View File

@ -10,13 +10,13 @@ class ServiceTest(DockerClientTestCase):
self.assertRaises(ValueError, lambda: Service(name='/'))
self.assertRaises(ValueError, lambda: Service(name='!'))
self.assertRaises(ValueError, lambda: Service(name='\xe2'))
self.assertRaises(ValueError, lambda: Service(name='_'))
self.assertRaises(ValueError, lambda: Service(name='____'))
self.assertRaises(ValueError, lambda: Service(name='foo_bar'))
self.assertRaises(ValueError, lambda: Service(name='__foo_bar__'))
Service('a')
Service('foo')
Service('foo_bar')
Service('__foo_bar__')
Service('_')
Service('_____')
def test_containers(self):
foo = self.create_service('foo')
@ -38,7 +38,7 @@ class ServiceTest(DockerClientTestCase):
self.assertIn('/bar_2', names)
def test_up_scale_down(self):
service = self.create_service('scaling_test')
service = self.create_service('scalingtest')
self.assertEqual(len(service.containers()), 0)
service.start()