2014-01-06 03:26:32 +01:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
2013-12-20 21:28:24 +01:00
|
|
|
from fig.service import Service
|
2014-10-13 20:14:46 +02:00
|
|
|
from fig.cli.docker_client import docker_client
|
2014-09-26 19:58:52 +02:00
|
|
|
from fig.progress_stream import stream_output
|
2014-04-25 23:58:21 +02:00
|
|
|
from .. import unittest
|
2013-12-09 18:36:44 +01:00
|
|
|
|
|
|
|
|
2014-01-06 12:22:46 +01:00
|
|
|
class DockerClientTestCase(unittest.TestCase):
|
2013-12-09 18:36:44 +01:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2014-10-13 20:14:46 +02:00
|
|
|
cls.client = docker_client()
|
2013-12-09 18:36:44 +01:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
for c in self.client.containers(all=True):
|
2014-01-02 16:27:51 +01:00
|
|
|
if c['Names'] and 'figtest' in c['Names'][0]:
|
|
|
|
self.client.kill(c['Id'])
|
|
|
|
self.client.remove_container(c['Id'])
|
2014-01-26 20:37:35 +01:00
|
|
|
for i in self.client.images():
|
2014-03-10 14:57:13 +01:00
|
|
|
if isinstance(i.get('Tag'), basestring) and 'figtest' in i['Tag']:
|
2014-01-26 20:37:35 +01:00
|
|
|
self.client.remove_image(i)
|
2013-12-09 18:36:44 +01:00
|
|
|
|
2013-12-09 22:39:11 +01:00
|
|
|
def create_service(self, name, **kwargs):
|
2014-02-21 19:12:51 +01:00
|
|
|
if 'command' not in kwargs:
|
|
|
|
kwargs['command'] = ["/bin/sleep", "300"]
|
2013-12-09 18:36:44 +01:00
|
|
|
return Service(
|
2014-01-02 16:27:51 +01:00
|
|
|
project='figtest',
|
2013-12-09 18:36:44 +01:00
|
|
|
name=name,
|
|
|
|
client=self.client,
|
2014-06-11 12:25:50 +02:00
|
|
|
image="busybox:latest",
|
2013-12-09 22:39:11 +01:00
|
|
|
**kwargs
|
2013-12-09 18:36:44 +01:00
|
|
|
)
|
|
|
|
|
2014-09-26 19:58:52 +02:00
|
|
|
def check_build(self, *args, **kwargs):
|
|
|
|
build_output = self.client.build(*args, **kwargs)
|
|
|
|
stream_output(build_output, open('/dev/null', 'w'))
|