Allow setting a one-off container name

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin 2015-08-26 13:33:03 -04:00
commit d2718bed99
5 changed files with 32 additions and 1 deletions

View file

@ -112,6 +112,7 @@ class CLITestCase(unittest.TestCase):
'--service-ports': None,
'--publish': [],
'--rm': None,
'--name': None,
})
_, _, call_kwargs = mock_client.create_container.mock_calls[0]
@ -141,6 +142,7 @@ class CLITestCase(unittest.TestCase):
'--service-ports': None,
'--publish': [],
'--rm': None,
'--name': None,
})
_, _, call_kwargs = mock_client.create_container.mock_calls[0]
self.assertEquals(call_kwargs['host_config']['RestartPolicy']['Name'], 'always')
@ -166,6 +168,7 @@ class CLITestCase(unittest.TestCase):
'--service-ports': None,
'--publish': [],
'--rm': True,
'--name': None,
})
_, _, call_kwargs = mock_client.create_container.mock_calls[0]
self.assertFalse('RestartPolicy' in call_kwargs['host_config'])
@ -195,4 +198,5 @@ class CLITestCase(unittest.TestCase):
'--service-ports': True,
'--publish': ['80:80'],
'--rm': None,
'--name': None,
})

View file

@ -150,6 +150,19 @@ class ServiceTest(unittest.TestCase):
self.assertEqual(opts['hostname'], 'name.sub', 'hostname')
self.assertEqual(opts['domainname'], 'domain.tld', 'domainname')
def test_get_container_create_options_with_name_option(self):
service = Service(
'foo',
image='foo',
client=self.mock_client,
container_name='foo1')
name = 'the_new_name'
opts = service._get_container_create_options(
{'name': name},
1,
one_off=True)
self.assertEqual(opts['name'], name)
def test_get_container_not_found(self):
self.mock_client.containers.return_value = []
service = Service('foo', client=self.mock_client, image='foo')