compose/tests/cli_test.py

78 lines
3.2 KiB
Python
Raw Normal View History

2014-01-09 16:30:36 +01:00
from __future__ import unicode_literals
from __future__ import absolute_import
2014-01-26 21:28:37 +01:00
from .testcases import DockerClientTestCase
2014-01-20 17:50:41 +01:00
from mock import patch
2014-03-03 13:25:38 +01:00
from fig.packages.six import StringIO
2014-01-09 16:30:36 +01:00
from fig.cli.main import TopLevelCommand
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-01-09 16:30:36 +01:00
self.command = TopLevelCommand()
self.command.base_dir = 'tests/fixtures/simple-figfile'
def tearDown(self):
self.command.project.kill()
self.command.project.remove_stopped()
def test_yaml_filename_check(self):
self.command.base_dir = 'tests/fixtures/longer-filename-figfile'
project = self.command.project
self.assertTrue( project.get_service('definedinyamlnotyml'), "Service: definedinyamlnotyml should have been loaded from .yaml file" )
2014-01-09 16:30:36 +01:00
def test_help(self):
self.assertRaises(SystemExit, lambda: self.command.dispatch(['-h'], None))
2014-01-20 17:50:41 +01:00
@patch('sys.stdout', new_callable=StringIO)
def test_ps(self, mock_stdout):
self.command.project.get_service('simple').create_container()
self.command.dispatch(['ps'], None)
2014-01-20 17:50:41 +01:00
self.assertIn('fig_simple_1', mock_stdout.getvalue())
2014-01-16 18:58:53 +01:00
@patch('sys.stdout', new_callable=StringIO)
def test_default_figfile(self, mock_stdout):
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
self.command.dispatch(['up', '-d'], None)
self.command.dispatch(['ps'], None)
output = mock_stdout.getvalue()
self.assertIn('fig_simple_1', output)
self.assertIn('fig_another_1', output)
self.assertNotIn('fig_yetanother_1', output)
@patch('sys.stdout', new_callable=StringIO)
def test_alternate_figfile(self, mock_stdout):
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()
self.assertNotIn('fig_simple_1', output)
self.assertNotIn('fig_another_1', output)
self.assertIn('fig_yetanother_1', output)
2014-01-16 18:58:53 +01:00
def test_scale(self):
project = self.command.project
self.command.scale({'SERVICE=NUM': ['simple=1']})
self.assertEqual(len(project.get_service('simple').containers()), 1)
self.command.scale({'SERVICE=NUM': ['simple=3', 'another=2']})
self.assertEqual(len(project.get_service('simple').containers()), 3)
self.assertEqual(len(project.get_service('another').containers()), 2)
self.command.scale({'SERVICE=NUM': ['simple=1', 'another=1']})
self.assertEqual(len(project.get_service('simple').containers()), 1)
self.assertEqual(len(project.get_service('another').containers()), 1)
self.command.scale({'SERVICE=NUM': ['simple=1', 'another=1']})
self.assertEqual(len(project.get_service('simple').containers()), 1)
self.assertEqual(len(project.get_service('another').containers()), 1)
self.command.scale({'SERVICE=NUM': ['simple=0', 'another=0']})
self.assertEqual(len(project.get_service('simple').containers()), 0)
self.assertEqual(len(project.get_service('another').containers()), 0)