2014-01-06 03:26:32 +01:00
|
|
|
from __future__ import unicode_literals
|
2014-04-25 23:58:21 +02:00
|
|
|
from .. import unittest
|
2014-08-02 22:31:08 +02:00
|
|
|
|
|
|
|
import mock
|
|
|
|
from fig.packages import docker
|
|
|
|
|
2013-12-20 21:28:24 +01:00
|
|
|
from fig.container import Container
|
2013-12-18 19:37:48 +01:00
|
|
|
|
2014-08-02 22:31:08 +02:00
|
|
|
|
2014-04-25 23:58:21 +02:00
|
|
|
class ContainerTest(unittest.TestCase):
|
2013-12-18 19:37:48 +01:00
|
|
|
def test_from_ps(self):
|
2014-04-25 23:58:21 +02:00
|
|
|
container = Container.from_ps(None, {
|
2013-12-18 19:37:48 +01:00
|
|
|
"Id":"abc",
|
2014-06-11 12:25:50 +02:00
|
|
|
"Image":"busybox:latest",
|
2013-12-18 19:37:48 +01:00
|
|
|
"Command":"sleep 300",
|
|
|
|
"Created":1387384730,
|
|
|
|
"Status":"Up 8 seconds",
|
|
|
|
"Ports":None,
|
|
|
|
"SizeRw":0,
|
|
|
|
"SizeRootFs":0,
|
2014-04-29 10:20:29 +02:00
|
|
|
"Names":["/figtest_db_1"]
|
2013-12-18 19:37:48 +01:00
|
|
|
}, has_been_inspected=True)
|
|
|
|
self.assertEqual(container.dictionary, {
|
2014-06-25 12:47:29 +02:00
|
|
|
"Id": "abc",
|
2014-06-11 12:25:50 +02:00
|
|
|
"Image":"busybox:latest",
|
2014-04-29 10:20:29 +02:00
|
|
|
"Name": "/figtest_db_1",
|
2013-12-18 19:37:48 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
def test_environment(self):
|
2014-04-25 23:58:21 +02:00
|
|
|
container = Container(None, {
|
2014-06-25 12:47:29 +02:00
|
|
|
'Id': 'abc',
|
2013-12-18 19:37:48 +01:00
|
|
|
'Config': {
|
|
|
|
'Env': [
|
|
|
|
'FOO=BAR',
|
|
|
|
'BAZ=DOGE',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}, has_been_inspected=True)
|
|
|
|
self.assertEqual(container.environment, {
|
|
|
|
'FOO': 'BAR',
|
|
|
|
'BAZ': 'DOGE',
|
|
|
|
})
|
2014-01-16 19:05:45 +01:00
|
|
|
|
|
|
|
def test_number(self):
|
2014-04-25 23:58:21 +02:00
|
|
|
container = Container.from_ps(None, {
|
2014-01-16 19:05:45 +01:00
|
|
|
"Id":"abc",
|
2014-06-11 12:25:50 +02:00
|
|
|
"Image":"busybox:latest",
|
2014-01-16 19:05:45 +01:00
|
|
|
"Command":"sleep 300",
|
|
|
|
"Created":1387384730,
|
|
|
|
"Status":"Up 8 seconds",
|
|
|
|
"Ports":None,
|
|
|
|
"SizeRw":0,
|
|
|
|
"SizeRootFs":0,
|
2014-04-29 10:20:29 +02:00
|
|
|
"Names":["/figtest_db_1"]
|
2014-01-16 19:05:45 +01:00
|
|
|
}, has_been_inspected=True)
|
|
|
|
self.assertEqual(container.number, 1)
|
2014-04-29 10:20:29 +02:00
|
|
|
|
|
|
|
def test_name(self):
|
|
|
|
container = Container.from_ps(None, {
|
|
|
|
"Id":"abc",
|
2014-06-11 12:25:50 +02:00
|
|
|
"Image":"busybox:latest",
|
2014-04-29 10:20:29 +02:00
|
|
|
"Command":"sleep 300",
|
|
|
|
"Names":["/figtest_db_1"]
|
|
|
|
}, has_been_inspected=True)
|
|
|
|
self.assertEqual(container.name, "figtest_db_1")
|
|
|
|
|
|
|
|
def test_name_without_project(self):
|
|
|
|
container = Container.from_ps(None, {
|
|
|
|
"Id":"abc",
|
2014-06-11 12:25:50 +02:00
|
|
|
"Image":"busybox:latest",
|
2014-04-29 10:20:29 +02:00
|
|
|
"Command":"sleep 300",
|
|
|
|
"Names":["/figtest_db_1"]
|
|
|
|
}, has_been_inspected=True)
|
|
|
|
self.assertEqual(container.name_without_project, "db_1")
|
2014-08-02 22:31:08 +02:00
|
|
|
|
|
|
|
def test_inspect_if_not_inspected(self):
|
|
|
|
mock_client = mock.create_autospec(docker.Client)
|
|
|
|
container = Container(mock_client, dict(Id="the_id"))
|
|
|
|
|
|
|
|
container.inspect_if_not_inspected()
|
|
|
|
mock_client.inspect_container.assert_called_once_with("the_id")
|
|
|
|
self.assertEqual(container.dictionary,
|
|
|
|
mock_client.inspect_container.return_value)
|
|
|
|
self.assertTrue(container.has_been_inspected)
|
|
|
|
|
|
|
|
container.inspect_if_not_inspected()
|
|
|
|
self.assertEqual(mock_client.inspect_container.call_count, 1)
|