2013-12-20 21:28:24 +01:00
|
|
|
from fig.project import Project
|
2013-12-19 17:55:12 +01:00
|
|
|
from .testcases import DockerClientTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectTest(DockerClientTestCase):
|
|
|
|
def test_from_dict(self):
|
2014-01-02 16:27:51 +01:00
|
|
|
project = Project.from_dicts('figtest', [
|
2013-12-19 17:55:12 +01:00
|
|
|
{
|
|
|
|
'name': 'web',
|
|
|
|
'image': 'ubuntu'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'db',
|
|
|
|
'image': 'ubuntu'
|
|
|
|
}
|
|
|
|
], self.client)
|
|
|
|
self.assertEqual(len(project.services), 2)
|
|
|
|
self.assertEqual(project.get_service('web').name, 'web')
|
|
|
|
self.assertEqual(project.get_service('web').options['image'], 'ubuntu')
|
|
|
|
self.assertEqual(project.get_service('db').name, 'db')
|
|
|
|
self.assertEqual(project.get_service('db').options['image'], 'ubuntu')
|
|
|
|
|
|
|
|
def test_from_dict_sorts_in_dependency_order(self):
|
2014-01-02 16:27:51 +01:00
|
|
|
project = Project.from_dicts('figtest', [
|
2013-12-19 17:55:12 +01:00
|
|
|
{
|
|
|
|
'name': 'web',
|
|
|
|
'image': 'ubuntu',
|
|
|
|
'links': ['db'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'db',
|
|
|
|
'image': 'ubuntu'
|
|
|
|
}
|
|
|
|
], self.client)
|
|
|
|
|
|
|
|
self.assertEqual(project.services[0].name, 'db')
|
|
|
|
self.assertEqual(project.services[1].name, 'web')
|
|
|
|
|
|
|
|
def test_get_service(self):
|
|
|
|
web = self.create_service('web')
|
|
|
|
project = Project('test', [web], self.client)
|
|
|
|
self.assertEqual(project.get_service('web'), web)
|
|
|
|
|
2013-12-20 19:30:23 +01:00
|
|
|
def test_create_containers(self):
|
2013-12-20 17:22:54 +01:00
|
|
|
web = self.create_service('web')
|
|
|
|
db = self.create_service('db')
|
|
|
|
project = Project('test', [web, db], self.client)
|
|
|
|
|
2013-12-31 14:02:08 +01:00
|
|
|
project.create_containers(service_names=['web'])
|
2013-12-20 19:30:23 +01:00
|
|
|
self.assertEqual(len(web.containers(stopped=True)), 1)
|
|
|
|
self.assertEqual(len(db.containers(stopped=True)), 0)
|
|
|
|
|
2013-12-31 14:02:08 +01:00
|
|
|
project.create_containers()
|
2013-12-31 13:37:17 +01:00
|
|
|
self.assertEqual(len(web.containers(stopped=True)), 1)
|
2013-12-20 19:30:23 +01:00
|
|
|
self.assertEqual(len(db.containers(stopped=True)), 1)
|
|
|
|
|
|
|
|
def test_start_stop_kill_remove(self):
|
2013-12-20 17:22:54 +01:00
|
|
|
web = self.create_service('web')
|
|
|
|
db = self.create_service('db')
|
2014-01-02 16:27:51 +01:00
|
|
|
project = Project('figtest', [web, db], self.client)
|
2013-12-20 17:22:54 +01:00
|
|
|
|
|
|
|
project.start()
|
|
|
|
|
|
|
|
self.assertEqual(len(web.containers()), 0)
|
|
|
|
self.assertEqual(len(db.containers()), 0)
|
2013-12-19 17:55:12 +01:00
|
|
|
|
2013-12-20 19:30:23 +01:00
|
|
|
web_container_1 = web.create_container()
|
|
|
|
web_container_2 = web.create_container()
|
|
|
|
db_container = db.create_container()
|
|
|
|
|
|
|
|
project.start(service_names=['web'])
|
|
|
|
self.assertEqual(set(c.name for c in project.containers()), set([web_container_1.name, web_container_2.name]))
|
|
|
|
|
2013-12-19 17:55:12 +01:00
|
|
|
project.start()
|
2013-12-20 19:30:23 +01:00
|
|
|
self.assertEqual(set(c.name for c in project.containers()), set([web_container_1.name, web_container_2.name, db_container.name]))
|
2013-12-19 17:55:12 +01:00
|
|
|
|
2013-12-20 19:30:23 +01:00
|
|
|
project.stop(service_names=['web'], timeout=1)
|
|
|
|
self.assertEqual(set(c.name for c in project.containers()), set([db_container.name]))
|
2013-12-19 17:55:12 +01:00
|
|
|
|
2013-12-20 19:30:23 +01:00
|
|
|
project.kill(service_names=['db'])
|
|
|
|
self.assertEqual(len(project.containers()), 0)
|
|
|
|
self.assertEqual(len(project.containers(stopped=True)), 3)
|
2013-12-19 17:55:12 +01:00
|
|
|
|
2013-12-20 19:30:23 +01:00
|
|
|
project.remove_stopped(service_names=['web'])
|
|
|
|
self.assertEqual(len(project.containers(stopped=True)), 1)
|
|
|
|
|
|
|
|
project.remove_stopped()
|
|
|
|
self.assertEqual(len(project.containers(stopped=True)), 0)
|