From 70ece003b5c98098b472b3180833dba0e2e5e7c6 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 5 Feb 2026 12:35:13 +0000 Subject: [PATCH] Add templates and tests --- tests/test_cli.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..4891cc4 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,85 @@ +"""Tests for CLI commands.""" + +import pytest +from click.testing import CliRunner +from pathlib import Path + +from mcp_server_cli.main import main + + +@pytest.fixture +def cli_runner(): + """Create a CLI runner for testing.""" + return CliRunner() + + +class TestCLIVersion: + """Tests for CLI version command.""" + + def test_version(self, cli_runner): + """Test --version option.""" + result = cli_runner.invoke(main, ["--version"]) + assert result.exit_code == 0 + assert "0.1.0" in result.output + + +class TestCLIServerCommands: + """Tests for server commands.""" + + def test_server_status_no_config(self, cli_runner): + """Test server status without config.""" + result = cli_runner.invoke(main, ["server", "status"]) + assert result.exit_code == 0 + + def test_config_show(self, cli_runner): + """Test config show command.""" + result = cli_runner.invoke(main, ["config", "show"]) + assert result.exit_code == 0 + + +class TestCLIToolCommands: + """Tests for tool commands.""" + + def test_tool_list(self, cli_runner): + """Test tool list command.""" + result = cli_runner.invoke(main, ["tool", "list"]) + assert result.exit_code == 0 + + def test_tool_add_nonexistent_file(self, cli_runner): + """Test tool add with nonexistent file.""" + result = cli_runner.invoke(main, ["tool", "add", "nonexistent.yaml"]) + assert result.exit_code != 0 or "nonexistent" in result.output.lower() + + +class TestCLIConfigCommands: + """Tests for config commands.""" + + def test_config_init(self, cli_runner, tmp_path): + """Test config init command.""" + output_file = tmp_path / "config.yaml" + result = cli_runner.invoke(main, ["config", "init", "-o", str(output_file)]) + assert result.exit_code == 0 + assert output_file.exists() + + def test_config_show_with_env(self, cli_runner): + """Test config show with environment variables.""" + result = cli_runner.invoke(main, ["config", "show"]) + assert result.exit_code == 0 + + +class TestCLIHealthCommand: + """Tests for health check command.""" + + def test_health_check_not_running(self, cli_runner): + """Test health check when server not running.""" + result = cli_runner.invoke(main, ["health"]) + assert result.exit_code == 0 or "not running" in result.output.lower() + + +class TestCLIInstallCompletions: + """Tests for shell completion installation.""" + + def test_install_completions(self, cli_runner): + """Test install completions command.""" + result = cli_runner.invoke(main, ["install"]) + assert result.exit_code == 0