feat(cli,display): add --health check and repo description column
Add --health option to verify Gitea connectivity and display version. Add Description column (truncated at 40 chars) with --no-desc to hide it. Add get_version() method to GiteaClient. fixes #14 fixes #15 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,9 @@ class TestMainNominal:
|
||||
|
||||
mock_client_cls.assert_called_once_with("http://localhost:3000", "test-token-123")
|
||||
mock_collect.assert_called_once_with(mock_client, include=None, exclude=None)
|
||||
mock_render.assert_called_once_with(mock_collect.return_value, sort_key="name")
|
||||
mock_render.assert_called_once_with(
|
||||
mock_collect.return_value, sort_key="name", show_description=True
|
||||
)
|
||||
|
||||
@patch("gitea_dashboard.cli.render_dashboard")
|
||||
@patch("gitea_dashboard.cli.collect_all")
|
||||
@@ -259,6 +261,96 @@ class TestParseArgsFormat:
|
||||
parse_args(["--format", "invalid"])
|
||||
|
||||
|
||||
class TestParseArgsHealth:
|
||||
"""Test --health argument parsing."""
|
||||
|
||||
def test_parse_args_health(self):
|
||||
"""--health sets health=True."""
|
||||
from gitea_dashboard.cli import parse_args
|
||||
|
||||
args = parse_args(["--health"])
|
||||
assert args.health is True
|
||||
|
||||
def test_parse_args_no_health_default(self):
|
||||
"""Without --health, health is False."""
|
||||
from gitea_dashboard.cli import parse_args
|
||||
|
||||
args = parse_args([])
|
||||
assert args.health is False
|
||||
|
||||
|
||||
class TestParseArgsNoDesc:
|
||||
"""Test --no-desc argument parsing."""
|
||||
|
||||
def test_parse_args_no_desc(self):
|
||||
"""--no-desc sets no_desc=True."""
|
||||
from gitea_dashboard.cli import parse_args
|
||||
|
||||
args = parse_args(["--no-desc"])
|
||||
assert args.no_desc is True
|
||||
|
||||
def test_parse_args_no_desc_default(self):
|
||||
"""Without --no-desc, no_desc is False."""
|
||||
from gitea_dashboard.cli import parse_args
|
||||
|
||||
args = parse_args([])
|
||||
assert args.no_desc is False
|
||||
|
||||
|
||||
class TestMainHealth:
|
||||
"""Test main() with --health."""
|
||||
|
||||
@patch("gitea_dashboard.cli.GiteaClient")
|
||||
def test_main_health_success(self, mock_client_cls, capsys):
|
||||
"""--health displays version and repo count, exits normally."""
|
||||
env = {"GITEA_TOKEN": "test-token"}
|
||||
mock_client = MagicMock()
|
||||
mock_client_cls.return_value = mock_client
|
||||
mock_client.get_version.return_value = {"version": "1.21.0"}
|
||||
mock_client.get_repos.return_value = [{"id": 1}, {"id": 2}, {"id": 3}]
|
||||
|
||||
with patch.dict("os.environ", env, clear=True):
|
||||
main(["--health"])
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "Gitea v1.21.0" in captured.err
|
||||
assert "3 repos accessibles" in captured.err
|
||||
|
||||
@patch("gitea_dashboard.cli.GiteaClient")
|
||||
def test_main_health_connection_error(self, mock_client_cls):
|
||||
"""--health with connection error exits with code 1."""
|
||||
env = {"GITEA_TOKEN": "test-token"}
|
||||
mock_client = MagicMock()
|
||||
mock_client_cls.return_value = mock_client
|
||||
mock_client.get_version.side_effect = requests.ConnectionError("refused")
|
||||
|
||||
with patch.dict("os.environ", env, clear=True):
|
||||
with pytest.raises(SystemExit) as exc_info:
|
||||
main(["--health"])
|
||||
|
||||
assert exc_info.value.code == 1
|
||||
|
||||
|
||||
class TestMainNoDesc:
|
||||
"""Test main() with --no-desc."""
|
||||
|
||||
@patch("gitea_dashboard.cli.render_dashboard")
|
||||
@patch("gitea_dashboard.cli.collect_all")
|
||||
@patch("gitea_dashboard.cli.GiteaClient")
|
||||
def test_main_passes_no_desc_to_render(self, mock_client_cls, mock_collect, mock_render):
|
||||
"""--no-desc passes show_description=False to render_dashboard."""
|
||||
env = {"GITEA_TOKEN": "test-token"}
|
||||
mock_client_cls.return_value = MagicMock()
|
||||
mock_collect.return_value = []
|
||||
|
||||
with patch.dict("os.environ", env, clear=True):
|
||||
main(["--no-desc"])
|
||||
|
||||
mock_render.assert_called_once_with(
|
||||
mock_collect.return_value, sort_key="name", show_description=False
|
||||
)
|
||||
|
||||
|
||||
class TestMainFormatJson:
|
||||
"""Test main() with --format json."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user