|
| 1 | +from unittest import mock |
| 2 | +from unittest.mock import MagicMock |
| 3 | + |
| 4 | +from click.testing import CliRunner |
| 5 | +from lightning_cloud.openapi import Externalv1Cluster |
| 6 | + |
| 7 | +from lightning_app.cli.cmd_clusters import ClusterList |
| 8 | +from lightning_app.cli.lightning_cli import cluster_logs |
| 9 | + |
| 10 | + |
| 11 | +@mock.patch("lightning_app.cli.lightning_cli.LightningClient", MagicMock()) |
| 12 | +@mock.patch("lightning_app.cli.cmd_clusters.LightningClient", MagicMock()) |
| 13 | +@mock.patch("lightning_app.cli.lightning_cli.AWSClusterManager.get_clusters") |
| 14 | +def test_show_logs_errors(get_clusters): |
| 15 | + """Test that the CLI prints the errors for the show logs command.""" |
| 16 | + |
| 17 | + runner = CliRunner() |
| 18 | + |
| 19 | + # Run without arguments |
| 20 | + get_clusters.return_value = ClusterList([]) |
| 21 | + result = runner.invoke(cluster_logs, []) |
| 22 | + |
| 23 | + assert result.exit_code == 2 |
| 24 | + assert "Usage: logs" in result.output |
| 25 | + |
| 26 | + # No clusters |
| 27 | + get_clusters.return_value = ClusterList([]) |
| 28 | + result = runner.invoke(cluster_logs, ["NonExistentCluster"]) |
| 29 | + |
| 30 | + assert result.exit_code == 1 |
| 31 | + assert "Error: You don't have any clusters" in result.output |
| 32 | + |
| 33 | + # One cluster |
| 34 | + clusters = ClusterList([Externalv1Cluster(name="MyFakeCluster", id="MyFakeCluster")]) |
| 35 | + get_clusters.return_value = clusters |
| 36 | + |
| 37 | + result = runner.invoke(cluster_logs, ["MyFakeClusterTwo"]) |
| 38 | + |
| 39 | + assert result.exit_code == 1 |
| 40 | + assert "Please select one of the following: [MyFakeCluster]" in str(result.output) |
0 commit comments