|
| 1 | +import pytest |
| 2 | +import show.main as show |
| 3 | +from click.testing import CliRunner |
| 4 | +from unittest.mock import MagicMock, patch |
| 5 | + |
| 6 | +EXPECTED_BASE_COMMAND = 'sudo ' |
| 7 | + |
| 8 | +@patch('show.main.run_command') |
| 9 | +@pytest.mark.parametrize( |
| 10 | + "cli_arguments,expected", |
| 11 | + [ |
| 12 | + ([], 'cat /var/log/syslog'), |
| 13 | + (['xcvrd'], "cat /var/log/syslog | grep 'xcvrd'"), |
| 14 | + (['-l', '10'], 'cat /var/log/syslog | tail -10'), |
| 15 | + (['-f'], 'tail -F /var/log/syslog'), |
| 16 | + ] |
| 17 | +) |
| 18 | +def test_show_logging_default(run_command, cli_arguments, expected): |
| 19 | + runner = CliRunner() |
| 20 | + result = runner.invoke(show.cli.commands["logging"], cli_arguments) |
| 21 | + run_command.assert_called_with(EXPECTED_BASE_COMMAND + expected, display_cmd=False) |
| 22 | + |
| 23 | +@patch('show.main.run_command') |
| 24 | +@patch('os.path.isfile', MagicMock(return_value=True)) |
| 25 | +@pytest.mark.parametrize( |
| 26 | + "cli_arguments,expected", |
| 27 | + [ |
| 28 | + ([], 'cat /var/log/syslog.1 /var/log/syslog'), |
| 29 | + (['xcvrd'], "cat /var/log/syslog.1 /var/log/syslog | grep 'xcvrd'"), |
| 30 | + (['-l', '10'], 'cat /var/log/syslog.1 /var/log/syslog | tail -10'), |
| 31 | + (['-f'], 'tail -F /var/log/syslog'), |
| 32 | + ] |
| 33 | +) |
| 34 | +def test_show_logging_syslog_1(run_command, cli_arguments, expected): |
| 35 | + runner = CliRunner() |
| 36 | + result = runner.invoke(show.cli.commands["logging"], cli_arguments) |
| 37 | + run_command.assert_called_with(EXPECTED_BASE_COMMAND + expected, display_cmd=False) |
| 38 | + |
| 39 | +@patch('show.main.run_command') |
| 40 | +@patch('os.path.exists', MagicMock(return_value=True)) |
| 41 | +@pytest.mark.parametrize( |
| 42 | + "cli_arguments,expected", |
| 43 | + [ |
| 44 | + ([], 'cat /var/log.tmpfs/syslog'), |
| 45 | + (['xcvrd'], "cat /var/log.tmpfs/syslog | grep 'xcvrd'"), |
| 46 | + (['-l', '10'], 'cat /var/log.tmpfs/syslog | tail -10'), |
| 47 | + (['-f'], 'tail -F /var/log.tmpfs/syslog'), |
| 48 | + ] |
| 49 | +) |
| 50 | +def test_show_logging_tmpfs(run_command, cli_arguments, expected): |
| 51 | + runner = CliRunner() |
| 52 | + result = runner.invoke(show.cli.commands["logging"], cli_arguments) |
| 53 | + run_command.assert_called_with(EXPECTED_BASE_COMMAND + expected, display_cmd=False) |
| 54 | + |
| 55 | +@patch('show.main.run_command') |
| 56 | +@patch('os.path.isfile', MagicMock(return_value=True)) |
| 57 | +@patch('os.path.exists', MagicMock(return_value=True)) |
| 58 | +@pytest.mark.parametrize( |
| 59 | + "cli_arguments,expected", |
| 60 | + [ |
| 61 | + ([], 'cat /var/log.tmpfs/syslog.1 /var/log.tmpfs/syslog'), |
| 62 | + (['xcvrd'], "cat /var/log.tmpfs/syslog.1 /var/log.tmpfs/syslog | grep 'xcvrd'"), |
| 63 | + (['-l', '10'], 'cat /var/log.tmpfs/syslog.1 /var/log.tmpfs/syslog | tail -10'), |
| 64 | + (['-f'], 'tail -F /var/log.tmpfs/syslog'), |
| 65 | + ] |
| 66 | +) |
| 67 | +def test_show_logging_tmpfs_syslog_1(run_command, cli_arguments, expected): |
| 68 | + runner = CliRunner() |
| 69 | + result = runner.invoke(show.cli.commands["logging"], cli_arguments) |
| 70 | + run_command.assert_called_with(EXPECTED_BASE_COMMAND + expected, display_cmd=False) |
0 commit comments