2014-01-09 16:30:36 +01:00
|
|
|
from __future__ import absolute_import
|
2014-08-08 18:41:52 +02:00
|
|
|
import sys
|
|
|
|
|
2014-07-30 22:11:11 +02:00
|
|
|
from six import StringIO
|
2014-06-08 14:37:42 +02:00
|
|
|
from mock import patch
|
2014-08-08 18:41:52 +02:00
|
|
|
|
|
|
|
from .testcases import DockerClientTestCase
|
2014-01-09 16:30:36 +01:00
|
|
|
from fig.cli.main import TopLevelCommand
|
|
|
|
|
2014-07-30 07:42:58 +02:00
|
|
|
|
2014-01-26 21:28:37 +01:00
|
|
|
class CLITestCase(DockerClientTestCase):
|
2014-01-09 16:30:36 +01:00
|
|
|
def setUp(self):
|
2014-01-26 21:28:37 +01:00
|
|
|
super(CLITestCase, self).setUp()
|
2014-06-08 15:03:58 +02:00
|
|
|
self.old_sys_exit = sys.exit
|
|
|
|
sys.exit = lambda code=0: None
|
2014-01-09 16:30:36 +01:00
|
|
|
self.command = TopLevelCommand()
|
|
|
|
self.command.base_dir = 'tests/fixtures/simple-figfile'
|
|
|
|
|
2014-01-20 17:47:58 +01:00
|
|
|
def tearDown(self):
|
2014-06-08 15:03:58 +02:00
|
|
|
sys.exit = self.old_sys_exit
|
2014-07-30 07:42:58 +02:00
|
|
|
self.project.kill()
|
|
|
|
self.project.remove_stopped()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def project(self):
|
|
|
|
return self.command.get_project(self.command.get_config_path())
|
2014-01-20 17:47:58 +01:00
|
|
|
|
2014-11-02 00:22:22 +01:00
|
|
|
def test_help(self):
|
|
|
|
old_base_dir = self.command.base_dir
|
|
|
|
self.command.base_dir = 'tests/fixtures/no-figfile'
|
|
|
|
with self.assertRaises(SystemExit) as exc_context:
|
|
|
|
self.command.dispatch(['help', 'up'], None)
|
|
|
|
self.assertIn('Usage: up [options] [SERVICE...]', str(exc_context.exception))
|
|
|
|
# self.project.kill() fails during teardown
|
|
|
|
# unless there is a figfile.
|
|
|
|
self.command.base_dir = old_base_dir
|
|
|
|
|
2014-01-20 17:50:41 +01:00
|
|
|
@patch('sys.stdout', new_callable=StringIO)
|
|
|
|
def test_ps(self, mock_stdout):
|
2014-07-30 07:42:58 +02:00
|
|
|
self.project.get_service('simple').create_container()
|
2014-01-09 16:31:37 +01:00
|
|
|
self.command.dispatch(['ps'], None)
|
2014-07-13 08:35:37 +02:00
|
|
|
self.assertIn('simplefigfile_simple_1', mock_stdout.getvalue())
|
2014-01-16 18:58:53 +01:00
|
|
|
|
2014-02-26 16:45:14 +01:00
|
|
|
@patch('sys.stdout', new_callable=StringIO)
|
2014-03-04 11:26:57 +01:00
|
|
|
def test_ps_default_figfile(self, mock_stdout):
|
2014-02-26 16:45:14 +01:00
|
|
|
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
|
|
|
self.command.dispatch(['ps'], None)
|
|
|
|
|
|
|
|
output = mock_stdout.getvalue()
|
2014-07-13 08:35:37 +02:00
|
|
|
self.assertIn('multiplefigfiles_simple_1', output)
|
|
|
|
self.assertIn('multiplefigfiles_another_1', output)
|
|
|
|
self.assertNotIn('multiplefigfiles_yetanother_1', output)
|
2014-02-26 16:45:14 +01:00
|
|
|
|
|
|
|
@patch('sys.stdout', new_callable=StringIO)
|
2014-03-04 11:26:57 +01:00
|
|
|
def test_ps_alternate_figfile(self, mock_stdout):
|
2014-02-26 16:45:14 +01:00
|
|
|
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
|
|
|
|
self.command.dispatch(['-f', 'fig2.yml', 'up', '-d'], None)
|
|
|
|
self.command.dispatch(['-f', 'fig2.yml', 'ps'], None)
|
|
|
|
|
|
|
|
output = mock_stdout.getvalue()
|
2014-07-13 08:35:37 +02:00
|
|
|
self.assertNotIn('multiplefigfiles_simple_1', output)
|
|
|
|
self.assertNotIn('multiplefigfiles_another_1', output)
|
|
|
|
self.assertIn('multiplefigfiles_yetanother_1', output)
|
2014-02-26 16:45:14 +01:00
|
|
|
|
2014-08-15 16:21:41 +02:00
|
|
|
@patch('fig.service.log')
|
|
|
|
def test_pull(self, mock_logging):
|
|
|
|
self.command.dispatch(['pull'], None)
|
|
|
|
mock_logging.info.assert_any_call('Pulling simple (busybox:latest)...')
|
|
|
|
mock_logging.info.assert_any_call('Pulling another (busybox:latest)...')
|
|
|
|
|
2014-07-20 10:27:05 +02:00
|
|
|
@patch('sys.stdout', new_callable=StringIO)
|
|
|
|
def test_build_no_cache(self, mock_stdout):
|
|
|
|
self.command.base_dir = 'tests/fixtures/simple-dockerfile'
|
|
|
|
self.command.dispatch(['build', 'simple'], None)
|
2014-07-24 20:47:39 +02:00
|
|
|
|
2014-07-20 10:27:05 +02:00
|
|
|
mock_stdout.truncate(0)
|
|
|
|
cache_indicator = 'Using cache'
|
|
|
|
self.command.dispatch(['build', 'simple'], None)
|
2014-07-24 20:47:39 +02:00
|
|
|
output = mock_stdout.getvalue()
|
2014-07-20 10:27:05 +02:00
|
|
|
self.assertIn(cache_indicator, output)
|
2014-07-24 20:47:39 +02:00
|
|
|
|
2014-07-20 10:27:05 +02:00
|
|
|
mock_stdout.truncate(0)
|
|
|
|
self.command.dispatch(['build', '--no-cache', 'simple'], None)
|
2014-07-24 20:47:39 +02:00
|
|
|
output = mock_stdout.getvalue()
|
2014-07-20 10:27:05 +02:00
|
|
|
self.assertNotIn(cache_indicator, output)
|
2014-11-03 23:46:01 +01:00
|
|
|
|
2014-06-07 15:44:07 +02:00
|
|
|
def test_up(self):
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
service = self.project.get_service('simple')
|
|
|
|
another = self.project.get_service('another')
|
2014-06-07 15:44:07 +02:00
|
|
|
self.assertEqual(len(service.containers()), 1)
|
2014-06-21 12:30:36 +02:00
|
|
|
self.assertEqual(len(another.containers()), 1)
|
2014-06-07 15:44:07 +02:00
|
|
|
|
2014-12-18 03:31:22 +01:00
|
|
|
# Ensure containers don't have stdin and stdout connected in -d mode
|
|
|
|
config = service.containers()[0].inspect()['Config']
|
|
|
|
self.assertFalse(config['AttachStderr'])
|
|
|
|
self.assertFalse(config['AttachStdout'])
|
|
|
|
self.assertFalse(config['AttachStdin'])
|
|
|
|
|
2014-06-08 14:33:08 +02:00
|
|
|
def test_up_with_links(self):
|
|
|
|
self.command.base_dir = 'tests/fixtures/links-figfile'
|
2014-06-08 15:16:59 +02:00
|
|
|
self.command.dispatch(['up', '-d', 'web'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
web = self.project.get_service('web')
|
|
|
|
db = self.project.get_service('db')
|
|
|
|
console = self.project.get_service('console')
|
2014-06-08 14:33:08 +02:00
|
|
|
self.assertEqual(len(web.containers()), 1)
|
|
|
|
self.assertEqual(len(db.containers()), 1)
|
|
|
|
self.assertEqual(len(console.containers()), 0)
|
|
|
|
|
2014-06-21 12:30:36 +02:00
|
|
|
def test_up_with_no_deps(self):
|
2014-06-08 14:33:08 +02:00
|
|
|
self.command.base_dir = 'tests/fixtures/links-figfile'
|
2014-06-21 12:30:36 +02:00
|
|
|
self.command.dispatch(['up', '-d', '--no-deps', 'web'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
web = self.project.get_service('web')
|
|
|
|
db = self.project.get_service('db')
|
|
|
|
console = self.project.get_service('console')
|
2014-06-08 14:33:08 +02:00
|
|
|
self.assertEqual(len(web.containers()), 1)
|
|
|
|
self.assertEqual(len(db.containers()), 0)
|
|
|
|
self.assertEqual(len(console.containers()), 0)
|
|
|
|
|
2014-06-08 15:16:14 +02:00
|
|
|
def test_up_with_recreate(self):
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
service = self.project.get_service('simple')
|
2014-06-08 15:16:14 +02:00
|
|
|
self.assertEqual(len(service.containers()), 1)
|
|
|
|
|
|
|
|
old_ids = [c.id for c in service.containers()]
|
|
|
|
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
|
|
|
self.assertEqual(len(service.containers()), 1)
|
|
|
|
|
|
|
|
new_ids = [c.id for c in service.containers()]
|
|
|
|
|
|
|
|
self.assertNotEqual(old_ids, new_ids)
|
|
|
|
|
|
|
|
def test_up_with_keep_old(self):
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
service = self.project.get_service('simple')
|
2014-06-08 15:16:14 +02:00
|
|
|
self.assertEqual(len(service.containers()), 1)
|
|
|
|
|
|
|
|
old_ids = [c.id for c in service.containers()]
|
|
|
|
|
2014-06-09 01:20:51 +02:00
|
|
|
self.command.dispatch(['up', '-d', '--no-recreate'], None)
|
2014-06-08 15:16:14 +02:00
|
|
|
self.assertEqual(len(service.containers()), 1)
|
|
|
|
|
|
|
|
new_ids = [c.id for c in service.containers()]
|
|
|
|
|
|
|
|
self.assertEqual(old_ids, new_ids)
|
|
|
|
|
2014-10-27 12:27:20 +01:00
|
|
|
@patch('dockerpty.start')
|
2014-07-02 12:28:02 +02:00
|
|
|
def test_run_service_without_links(self, mock_stdout):
|
|
|
|
self.command.base_dir = 'tests/fixtures/links-figfile'
|
|
|
|
self.command.dispatch(['run', 'console', '/bin/true'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
self.assertEqual(len(self.project.containers()), 0)
|
2014-06-08 15:03:58 +02:00
|
|
|
|
2014-12-18 03:31:22 +01:00
|
|
|
# Ensure stdin/out was open
|
|
|
|
container = self.project.containers(stopped=True, one_off=True)[0]
|
|
|
|
config = container.inspect()['Config']
|
|
|
|
self.assertTrue(config['AttachStderr'])
|
|
|
|
self.assertTrue(config['AttachStdout'])
|
|
|
|
self.assertTrue(config['AttachStdin'])
|
|
|
|
|
2014-10-27 12:27:20 +01:00
|
|
|
@patch('dockerpty.start')
|
2014-07-05 10:19:54 +02:00
|
|
|
def test_run_service_with_links(self, __):
|
2014-06-08 15:03:58 +02:00
|
|
|
self.command.base_dir = 'tests/fixtures/links-figfile'
|
2014-06-08 15:16:59 +02:00
|
|
|
self.command.dispatch(['run', 'web', '/bin/true'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
db = self.project.get_service('db')
|
|
|
|
console = self.project.get_service('console')
|
2014-06-08 15:03:58 +02:00
|
|
|
self.assertEqual(len(db.containers()), 1)
|
|
|
|
self.assertEqual(len(console.containers()), 0)
|
|
|
|
|
2014-10-27 12:27:20 +01:00
|
|
|
@patch('dockerpty.start')
|
2014-07-05 10:19:54 +02:00
|
|
|
def test_run_with_no_deps(self, __):
|
2014-06-08 15:03:58 +02:00
|
|
|
self.command.base_dir = 'tests/fixtures/links-figfile'
|
2014-06-21 12:30:36 +02:00
|
|
|
self.command.dispatch(['run', '--no-deps', 'web', '/bin/true'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
db = self.project.get_service('db')
|
2014-06-08 15:03:58 +02:00
|
|
|
self.assertEqual(len(db.containers()), 0)
|
|
|
|
|
2014-10-27 12:27:20 +01:00
|
|
|
@patch('dockerpty.start')
|
2014-07-05 10:19:54 +02:00
|
|
|
def test_run_does_not_recreate_linked_containers(self, __):
|
2014-06-08 15:16:14 +02:00
|
|
|
self.command.base_dir = 'tests/fixtures/links-figfile'
|
2014-06-08 15:16:59 +02:00
|
|
|
self.command.dispatch(['up', '-d', 'db'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
db = self.project.get_service('db')
|
2014-06-08 15:16:14 +02:00
|
|
|
self.assertEqual(len(db.containers()), 1)
|
|
|
|
|
|
|
|
old_ids = [c.id for c in db.containers()]
|
|
|
|
|
2014-06-08 15:16:59 +02:00
|
|
|
self.command.dispatch(['run', 'web', '/bin/true'], None)
|
2014-06-08 15:16:14 +02:00
|
|
|
self.assertEqual(len(db.containers()), 1)
|
|
|
|
|
|
|
|
new_ids = [c.id for c in db.containers()]
|
|
|
|
|
|
|
|
self.assertEqual(old_ids, new_ids)
|
|
|
|
|
2014-10-27 12:27:20 +01:00
|
|
|
@patch('dockerpty.start')
|
2014-07-05 10:19:54 +02:00
|
|
|
def test_run_without_command(self, __):
|
|
|
|
self.command.base_dir = 'tests/fixtures/commands-figfile'
|
2014-09-26 19:58:52 +02:00
|
|
|
self.check_build('tests/fixtures/simple-dockerfile', tag='figtest_test')
|
2014-07-05 10:19:54 +02:00
|
|
|
|
2014-07-30 07:42:58 +02:00
|
|
|
for c in self.project.containers(stopped=True, one_off=True):
|
2014-07-05 10:19:54 +02:00
|
|
|
c.remove()
|
|
|
|
|
|
|
|
self.command.dispatch(['run', 'implicit'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
service = self.project.get_service('implicit')
|
2014-07-05 10:19:54 +02:00
|
|
|
containers = service.containers(stopped=True, one_off=True)
|
|
|
|
self.assertEqual(
|
|
|
|
[c.human_readable_command for c in containers],
|
|
|
|
[u'/bin/sh -c echo "success"'],
|
|
|
|
)
|
|
|
|
|
|
|
|
self.command.dispatch(['run', 'explicit'], None)
|
2014-07-30 07:42:58 +02:00
|
|
|
service = self.project.get_service('explicit')
|
2014-07-05 10:19:54 +02:00
|
|
|
containers = service.containers(stopped=True, one_off=True)
|
|
|
|
self.assertEqual(
|
|
|
|
[c.human_readable_command for c in containers],
|
|
|
|
[u'/bin/true'],
|
|
|
|
)
|
|
|
|
|
2014-10-27 12:27:20 +01:00
|
|
|
@patch('dockerpty.start')
|
2014-08-17 14:13:28 +02:00
|
|
|
def test_run_service_with_entrypoint_overridden(self, _):
|
|
|
|
self.command.base_dir = 'tests/fixtures/dockerfile_with_entrypoint'
|
|
|
|
name = 'service'
|
|
|
|
self.command.dispatch(
|
|
|
|
['run', '--entrypoint', '/bin/echo', name, 'helloworld'],
|
|
|
|
None
|
|
|
|
)
|
|
|
|
service = self.project.get_service(name)
|
|
|
|
container = service.containers(stopped=True, one_off=True)[0]
|
|
|
|
self.assertEqual(
|
|
|
|
container.human_readable_command,
|
|
|
|
u'/bin/echo helloworld'
|
|
|
|
)
|
|
|
|
|
2014-10-27 12:27:20 +01:00
|
|
|
@patch('dockerpty.start')
|
2014-10-07 17:03:40 +02:00
|
|
|
def test_run_service_with_environement_overridden(self, _):
|
|
|
|
name = 'service'
|
|
|
|
self.command.base_dir = 'tests/fixtures/environment-figfile'
|
|
|
|
self.command.dispatch(
|
|
|
|
['run', '-e', 'foo=notbar', '-e', 'allo=moto=bobo',
|
|
|
|
'-e', 'alpha=beta', name],
|
|
|
|
None
|
|
|
|
)
|
|
|
|
service = self.project.get_service(name)
|
|
|
|
container = service.containers(stopped=True, one_off=True)[0]
|
|
|
|
# env overriden
|
|
|
|
self.assertEqual('notbar', container.environment['foo'])
|
|
|
|
# keep environement from yaml
|
|
|
|
self.assertEqual('world', container.environment['hello'])
|
|
|
|
# added option from command line
|
|
|
|
self.assertEqual('beta', container.environment['alpha'])
|
|
|
|
# make sure a value with a = don't crash out
|
|
|
|
self.assertEqual('moto=bobo', container.environment['allo'])
|
|
|
|
|
2014-09-16 00:18:03 +02:00
|
|
|
@patch('dockerpty.start')
|
|
|
|
def test_run_service_without_map_ports(self, __):
|
|
|
|
# create one off container
|
|
|
|
self.command.base_dir = 'tests/fixtures/ports-figfile'
|
|
|
|
self.command.dispatch(['run', '-d', 'simple'], None)
|
|
|
|
container = self.project.get_service('simple').containers(one_off=True)[0]
|
|
|
|
|
|
|
|
# get port information
|
|
|
|
port_random = container.get_local_port(3000)
|
|
|
|
port_assigned = container.get_local_port(3001)
|
|
|
|
|
|
|
|
# close all one off containers we just created
|
|
|
|
container.stop()
|
|
|
|
|
|
|
|
# check the ports
|
|
|
|
self.assertEqual(port_random, None)
|
|
|
|
self.assertEqual(port_assigned, None)
|
|
|
|
|
|
|
|
@patch('dockerpty.start')
|
|
|
|
def test_run_service_with_map_ports(self, __):
|
|
|
|
# create one off container
|
|
|
|
self.command.base_dir = 'tests/fixtures/ports-figfile'
|
|
|
|
self.command.dispatch(['run', '-d', '--service-ports', 'simple'], None)
|
|
|
|
container = self.project.get_service('simple').containers(one_off=True)[0]
|
|
|
|
|
|
|
|
# get port information
|
|
|
|
port_random = container.get_local_port(3000)
|
|
|
|
port_assigned = container.get_local_port(3001)
|
|
|
|
|
|
|
|
# close all one off containers we just created
|
|
|
|
container.stop()
|
|
|
|
|
|
|
|
# check the ports
|
|
|
|
self.assertNotEqual(port_random, None)
|
|
|
|
self.assertIn("0.0.0.0", port_random)
|
|
|
|
self.assertEqual(port_assigned, "0.0.0.0:9999")
|
|
|
|
|
2014-03-04 11:49:07 +01:00
|
|
|
def test_rm(self):
|
2014-07-30 07:42:58 +02:00
|
|
|
service = self.project.get_service('simple')
|
2014-03-04 11:49:07 +01:00
|
|
|
service.create_container()
|
|
|
|
service.kill()
|
|
|
|
self.assertEqual(len(service.containers(stopped=True)), 1)
|
|
|
|
self.command.dispatch(['rm', '--force'], None)
|
|
|
|
self.assertEqual(len(service.containers(stopped=True)), 0)
|
|
|
|
|
2014-11-03 23:46:01 +01:00
|
|
|
def test_kill(self):
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
|
|
|
service = self.project.get_service('simple')
|
|
|
|
self.assertEqual(len(service.containers()), 1)
|
|
|
|
self.assertTrue(service.containers()[0].is_running)
|
|
|
|
|
|
|
|
self.command.dispatch(['kill'], None)
|
|
|
|
|
|
|
|
self.assertEqual(len(service.containers(stopped=True)), 1)
|
|
|
|
self.assertFalse(service.containers(stopped=True)[0].is_running)
|
|
|
|
|
|
|
|
def test_kill_signal_sigint(self):
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
|
|
|
service = self.project.get_service('simple')
|
|
|
|
self.assertEqual(len(service.containers()), 1)
|
|
|
|
self.assertTrue(service.containers()[0].is_running)
|
|
|
|
|
|
|
|
self.command.dispatch(['kill', '-s', 'SIGINT'], None)
|
|
|
|
|
|
|
|
self.assertEqual(len(service.containers()), 1)
|
|
|
|
# The container is still running. It has been only interrupted
|
|
|
|
self.assertTrue(service.containers()[0].is_running)
|
|
|
|
|
|
|
|
def test_kill_interrupted_service(self):
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
|
|
|
service = self.project.get_service('simple')
|
|
|
|
self.command.dispatch(['kill', '-s', 'SIGINT'], None)
|
|
|
|
self.assertTrue(service.containers()[0].is_running)
|
|
|
|
|
|
|
|
self.command.dispatch(['kill', '-s', 'SIGKILL'], None)
|
|
|
|
|
|
|
|
self.assertEqual(len(service.containers(stopped=True)), 1)
|
|
|
|
self.assertFalse(service.containers(stopped=True)[0].is_running)
|
|
|
|
|
2014-08-08 22:11:34 +02:00
|
|
|
def test_restart(self):
|
|
|
|
service = self.project.get_service('simple')
|
|
|
|
container = service.create_container()
|
|
|
|
service.start_container(container)
|
|
|
|
started_at = container.dictionary['State']['StartedAt']
|
|
|
|
self.command.dispatch(['restart'], None)
|
|
|
|
container.inspect()
|
|
|
|
self.assertNotEqual(
|
|
|
|
container.dictionary['State']['FinishedAt'],
|
|
|
|
'0001-01-01T00:00:00Z',
|
|
|
|
)
|
|
|
|
self.assertNotEqual(
|
|
|
|
container.dictionary['State']['StartedAt'],
|
|
|
|
started_at,
|
|
|
|
)
|
|
|
|
|
2014-01-16 18:58:53 +01:00
|
|
|
def test_scale(self):
|
2014-07-30 07:42:58 +02:00
|
|
|
project = self.project
|
2014-01-16 18:58:53 +01:00
|
|
|
|
2014-07-30 07:42:58 +02:00
|
|
|
self.command.scale(project, {'SERVICE=NUM': ['simple=1']})
|
2014-01-16 18:58:53 +01:00
|
|
|
self.assertEqual(len(project.get_service('simple').containers()), 1)
|
|
|
|
|
2014-07-30 07:42:58 +02:00
|
|
|
self.command.scale(project, {'SERVICE=NUM': ['simple=3', 'another=2']})
|
2014-01-16 18:58:53 +01:00
|
|
|
self.assertEqual(len(project.get_service('simple').containers()), 3)
|
|
|
|
self.assertEqual(len(project.get_service('another').containers()), 2)
|
|
|
|
|
2014-07-30 07:42:58 +02:00
|
|
|
self.command.scale(project, {'SERVICE=NUM': ['simple=1', 'another=1']})
|
2014-01-16 18:58:53 +01:00
|
|
|
self.assertEqual(len(project.get_service('simple').containers()), 1)
|
|
|
|
self.assertEqual(len(project.get_service('another').containers()), 1)
|
|
|
|
|
2014-07-30 07:42:58 +02:00
|
|
|
self.command.scale(project, {'SERVICE=NUM': ['simple=1', 'another=1']})
|
2014-01-16 18:58:53 +01:00
|
|
|
self.assertEqual(len(project.get_service('simple').containers()), 1)
|
|
|
|
self.assertEqual(len(project.get_service('another').containers()), 1)
|
|
|
|
|
2014-07-30 07:42:58 +02:00
|
|
|
self.command.scale(project, {'SERVICE=NUM': ['simple=0', 'another=0']})
|
2014-01-16 18:58:53 +01:00
|
|
|
self.assertEqual(len(project.get_service('simple').containers()), 0)
|
|
|
|
self.assertEqual(len(project.get_service('another').containers()), 0)
|
2014-08-08 18:41:52 +02:00
|
|
|
|
|
|
|
def test_port(self):
|
|
|
|
self.command.base_dir = 'tests/fixtures/ports-figfile'
|
|
|
|
self.command.dispatch(['up', '-d'], None)
|
|
|
|
container = self.project.get_service('simple').get_container()
|
|
|
|
|
|
|
|
@patch('sys.stdout', new_callable=StringIO)
|
|
|
|
def get_port(number, mock_stdout):
|
|
|
|
self.command.dispatch(['port', 'simple', str(number)], None)
|
|
|
|
return mock_stdout.getvalue().rstrip()
|
|
|
|
|
|
|
|
self.assertEqual(get_port(3000), container.get_local_port(3000))
|
|
|
|
self.assertEqual(get_port(3001), "0.0.0.0:9999")
|
|
|
|
self.assertEqual(get_port(3002), "")
|