Resolves #1066, use labels to identify containers
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
28d2aff8b8
commit
ed50a0a3a0
9 changed files with 138 additions and 102 deletions
|
|
@ -5,6 +5,7 @@ import mock
|
|||
import docker
|
||||
|
||||
from compose.container import Container
|
||||
from compose.container import get_container_name
|
||||
|
||||
|
||||
class ContainerTest(unittest.TestCase):
|
||||
|
|
@ -23,6 +24,13 @@ class ContainerTest(unittest.TestCase):
|
|||
"NetworkSettings": {
|
||||
"Ports": {},
|
||||
},
|
||||
"Config": {
|
||||
"Labels": {
|
||||
"com.docker.compose.project": "composetest",
|
||||
"com.docker.compose.service": "web",
|
||||
"com.docker.compose.container_number": 7,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
def test_from_ps(self):
|
||||
|
|
@ -65,10 +73,8 @@ class ContainerTest(unittest.TestCase):
|
|||
})
|
||||
|
||||
def test_number(self):
|
||||
container = Container.from_ps(None,
|
||||
self.container_dict,
|
||||
has_been_inspected=True)
|
||||
self.assertEqual(container.number, 1)
|
||||
container = Container(None, self.container_dict, has_been_inspected=True)
|
||||
self.assertEqual(container.number, 7)
|
||||
|
||||
def test_name(self):
|
||||
container = Container.from_ps(None,
|
||||
|
|
@ -77,10 +83,8 @@ class ContainerTest(unittest.TestCase):
|
|||
self.assertEqual(container.name, "composetest_db_1")
|
||||
|
||||
def test_name_without_project(self):
|
||||
container = Container.from_ps(None,
|
||||
self.container_dict,
|
||||
has_been_inspected=True)
|
||||
self.assertEqual(container.name_without_project, "db_1")
|
||||
container = Container(None, self.container_dict, has_been_inspected=True)
|
||||
self.assertEqual(container.name_without_project, "web_7")
|
||||
|
||||
def test_inspect_if_not_inspected(self):
|
||||
mock_client = mock.create_autospec(docker.Client)
|
||||
|
|
@ -130,3 +134,12 @@ class ContainerTest(unittest.TestCase):
|
|||
self.assertEqual(container.get('Status'), "Up 8 seconds")
|
||||
self.assertEqual(container.get('HostConfig.VolumesFrom'), ["volume_id"])
|
||||
self.assertEqual(container.get('Foo.Bar.DoesNotExist'), None)
|
||||
|
||||
|
||||
class GetContainerNameTestCase(unittest.TestCase):
|
||||
|
||||
def test_get_container_name(self):
|
||||
self.assertIsNone(get_container_name({}))
|
||||
self.assertEqual(get_container_name({'Name': 'myproject_db_1'}), 'myproject_db_1')
|
||||
self.assertEqual(get_container_name({'Names': ['/myproject_db_1', '/myproject_web_1/db']}), 'myproject_db_1')
|
||||
self.assertEqual(get_container_name({'Names': ['/swarm-host-1/myproject_db_1', '/swarm-host-1/myproject_web_1/db']}), 'myproject_db_1')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue