Merge pull request #2720 from seguins/2227-improvements-logs
Add flags on logs
This commit is contained in:
commit
0b3561a7d5
9 changed files with 104 additions and 18 deletions
|
|
@ -398,6 +398,8 @@ class CLITestCase(DockerClientTestCase):
|
|||
|
||||
assert 'simple_1 | simple' in result.stdout
|
||||
assert 'another_1 | another' in result.stdout
|
||||
assert 'simple_1 exited with code 0' in result.stdout
|
||||
assert 'another_1 exited with code 0' in result.stdout
|
||||
|
||||
@v2_only()
|
||||
def test_up(self):
|
||||
|
|
@ -1159,6 +1161,42 @@ class CLITestCase(DockerClientTestCase):
|
|||
def test_logs_invalid_service_name(self):
|
||||
self.dispatch(['logs', 'madeupname'], returncode=1)
|
||||
|
||||
def test_logs_follow(self):
|
||||
self.base_dir = 'tests/fixtures/echo-services'
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
||||
result = self.dispatch(['logs', '-f'])
|
||||
|
||||
assert result.stdout.count('\n') == 5
|
||||
assert 'simple' in result.stdout
|
||||
assert 'another' in result.stdout
|
||||
assert 'exited with code 0' in result.stdout
|
||||
|
||||
def test_logs_unfollow(self):
|
||||
self.base_dir = 'tests/fixtures/logs-composefile'
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
||||
result = self.dispatch(['logs'])
|
||||
|
||||
assert result.stdout.count('\n') >= 1
|
||||
assert 'exited with code 0' not in result.stdout
|
||||
|
||||
def test_logs_timestamps(self):
|
||||
self.base_dir = 'tests/fixtures/echo-services'
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
||||
result = self.dispatch(['logs', '-f', '-t'], None)
|
||||
|
||||
self.assertRegexpMatches(result.stdout, '(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})')
|
||||
|
||||
def test_logs_tail(self):
|
||||
self.base_dir = 'tests/fixtures/logs-tail-composefile'
|
||||
self.dispatch(['up'], None)
|
||||
|
||||
result = self.dispatch(['logs', '--tail', '2'], None)
|
||||
|
||||
assert result.stdout.count('\n') == 3
|
||||
|
||||
def test_kill(self):
|
||||
self.dispatch(['up', '-d'], None)
|
||||
service = self.project.get_service('simple')
|
||||
|
|
|
|||
6
tests/fixtures/logs-composefile/docker-compose.yml
vendored
Normal file
6
tests/fixtures/logs-composefile/docker-compose.yml
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
simple:
|
||||
image: busybox:latest
|
||||
command: sh -c "echo hello && sleep 200"
|
||||
another:
|
||||
image: busybox:latest
|
||||
command: sh -c "echo test"
|
||||
3
tests/fixtures/logs-tail-composefile/docker-compose.yml
vendored
Normal file
3
tests/fixtures/logs-tail-composefile/docker-compose.yml
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
simple:
|
||||
image: busybox:latest
|
||||
command: sh -c "echo a && echo b && echo c && echo d"
|
||||
|
|
@ -17,7 +17,7 @@ def build_mock_container(reader):
|
|||
name_without_project='web_1',
|
||||
has_api_logs=True,
|
||||
log_stream=None,
|
||||
attach=reader,
|
||||
logs=reader,
|
||||
wait=mock.Mock(return_value=0),
|
||||
)
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ def mock_container():
|
|||
class TestLogPrinter(object):
|
||||
|
||||
def test_single_container(self, output_stream, mock_container):
|
||||
LogPrinter([mock_container], output=output_stream).run()
|
||||
LogPrinter([mock_container], output=output_stream, log_args={'follow': True}).run()
|
||||
|
||||
output = output_stream.getvalue()
|
||||
assert 'hello' in output
|
||||
|
|
@ -47,6 +47,15 @@ class TestLogPrinter(object):
|
|||
# Call count is 2 lines + "container exited line"
|
||||
assert output_stream.flush.call_count == 3
|
||||
|
||||
def test_single_container_without_stream(self, output_stream, mock_container):
|
||||
LogPrinter([mock_container], output=output_stream).run()
|
||||
|
||||
output = output_stream.getvalue()
|
||||
assert 'hello' in output
|
||||
assert 'world' in output
|
||||
# Call count is 2 lines
|
||||
assert output_stream.flush.call_count == 2
|
||||
|
||||
def test_monochrome(self, output_stream, mock_container):
|
||||
LogPrinter([mock_container], output=output_stream, monochrome=True).run()
|
||||
assert '\033[' not in output_stream.getvalue()
|
||||
|
|
@ -86,3 +95,4 @@ class TestLogPrinter(object):
|
|||
|
||||
output = output_stream.getvalue()
|
||||
assert "WARNING: no logs are available with the 'none' log driver\n" in output
|
||||
assert "exited with code" not in output
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class CLIMainTestCase(unittest.TestCase):
|
|||
mock_container('another', 1),
|
||||
]
|
||||
service_names = ['web', 'db']
|
||||
log_printer = build_log_printer(containers, service_names, True, False)
|
||||
log_printer = build_log_printer(containers, service_names, True, False, {'follow': True})
|
||||
self.assertEqual(log_printer.containers, containers[:3])
|
||||
|
||||
def test_build_log_printer_all_services(self):
|
||||
|
|
@ -43,7 +43,7 @@ class CLIMainTestCase(unittest.TestCase):
|
|||
mock_container('other', 1),
|
||||
]
|
||||
service_names = []
|
||||
log_printer = build_log_printer(containers, service_names, True, False)
|
||||
log_printer = build_log_printer(containers, service_names, True, False, {'follow': True})
|
||||
self.assertEqual(log_printer.containers, containers)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue