mirror of https://github.com/docker/compose.git
Merge pull request #6312 from docker/6311-container_slug_none
Don't attempt to truncate a None value in Container.slug
This commit is contained in:
commit
9b12f489aa
|
@ -96,6 +96,8 @@ class Container(object):
|
|||
|
||||
@property
|
||||
def slug(self):
|
||||
if not self.full_slug:
|
||||
return None
|
||||
return truncate_id(self.full_slug)
|
||||
|
||||
@property
|
||||
|
|
|
@ -5,6 +5,7 @@ import docker
|
|||
|
||||
from .. import mock
|
||||
from .. import unittest
|
||||
from compose.const import LABEL_SLUG
|
||||
from compose.container import Container
|
||||
from compose.container import get_container_name
|
||||
|
||||
|
@ -87,7 +88,7 @@ class ContainerTest(unittest.TestCase):
|
|||
assert container.name == "composetest_db_1"
|
||||
|
||||
def test_name_without_project(self):
|
||||
self.container_dict['Name'] = "/composetest_web_7"
|
||||
self.container_dict['Name'] = "/composetest_web_7_092cd63296fd"
|
||||
container = Container(None, self.container_dict, has_been_inspected=True)
|
||||
assert container.name_without_project == "web_7_092cd63296fd"
|
||||
|
||||
|
@ -96,6 +97,12 @@ class ContainerTest(unittest.TestCase):
|
|||
container = Container(None, self.container_dict, has_been_inspected=True)
|
||||
assert container.name_without_project == "custom_name_of_container"
|
||||
|
||||
def test_name_without_project_noslug(self):
|
||||
self.container_dict['Name'] = "/composetest_web_7"
|
||||
del self.container_dict['Config']['Labels'][LABEL_SLUG]
|
||||
container = Container(None, self.container_dict, has_been_inspected=True)
|
||||
assert container.name_without_project == 'web_7'
|
||||
|
||||
def test_inspect_if_not_inspected(self):
|
||||
mock_client = mock.create_autospec(docker.APIClient)
|
||||
container = Container(mock_client, dict(Id="the_id"))
|
||||
|
|
Loading…
Reference in New Issue