From cb8d45121f408035a4672ebc104b5b934071bfbb Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 20:51:50 +0000 Subject: [PATCH] Add test suite for confgen --- app/tests/test_cli.py | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 app/tests/test_cli.py diff --git a/app/tests/test_cli.py b/app/tests/test_cli.py new file mode 100644 index 0000000..91f55b3 --- /dev/null +++ b/app/tests/test_cli.py @@ -0,0 +1,109 @@ +"""Tests for CLI commands.""" + +import tempfile +from pathlib import Path +from click.testing import CliRunner + +from src.confgen.cli import main + + +class TestCLI: + """Tests for CLI commands.""" + + def setup_method(self): + """Set up test fixtures.""" + self.runner = CliRunner() + + def test_main_help(self): + """Test that main command shows help.""" + result = self.runner.invoke(main, ["--help"]) + + assert result.exit_code == 0 + assert "Generate, validate" in result.output + + def test_generate_command_exists(self): + """Test that generate command exists.""" + result = self.runner.invoke(main, ["generate", "--help"]) + + assert result.exit_code == 0 + assert "Generate a configuration file" in result.output + + def test_list_command_exists(self): + """Test that list command exists.""" + result = self.runner.invoke(main, ["list", "--help"]) + + assert result.exit_code == 0 + assert "List available templates" in result.output + + def test_validate_command_exists(self): + """Test that validate command exists.""" + result = self.runner.invoke(main, ["validate", "--help"]) + + assert result.exit_code == 0 + assert "Validate a configuration file" in result.output + + def test_edit_command_exists(self): + """Test that edit command exists.""" + result = self.runner.invoke(main, ["edit", "--help"]) + + assert result.exit_code == 0 + assert "interactive editor" in result.output.lower() + + def test_generate_without_template_shows_error(self): + """Test that generate without template shows error.""" + result = self.runner.invoke(main, ["generate"]) + + assert result.exit_code != 0 + assert "Missing argument" in result.output + + def test_generate_with_nonexistent_template(self): + """Test that generate with nonexistent template shows error.""" + with tempfile.TemporaryDirectory() as tmpdir: + result = self.runner.invoke(main, ["generate", "--template", "nonexistent", "--config-dir", tmpdir]) + + assert result.exit_code != 0 + + def test_list_with_templates_option(self): + """Test list with --templates option.""" + with tempfile.TemporaryDirectory() as tmpdir: + confgen_yaml = Path(tmpdir) / "confgen.yaml" + confgen_yaml.write_text("templates: {}\nenvironments: {}\n") + result = self.runner.invoke(main, ["--config-dir", tmpdir, "list", "--templates"]) + + assert result.exit_code == 0 + + def test_list_with_environments_option(self): + """Test list with --environments option.""" + with tempfile.TemporaryDirectory() as tmpdir: + confgen_yaml = Path(tmpdir) / "confgen.yaml" + confgen_yaml.write_text("templates: {}\nenvironments: {}\n") + result = self.runner.invoke(main, ["--config-dir", tmpdir, "list", "--environments"]) + + assert result.exit_code == 0 + + def test_version_option(self): + """Test --version option.""" + result = self.runner.invoke(main, ["--version"]) + + assert result.exit_code == 0 + assert "0.1.0" in result.output + + def test_environment_option(self): + """Test --environment option.""" + with tempfile.TemporaryDirectory() as tmpdir: + result = self.runner.invoke(main, ["--environment", "staging", "--config-dir", tmpdir, "list"]) + + assert result.exit_code == 0 + + def test_validate_without_file_shows_error(self): + """Test validate without file shows error.""" + result = self.runner.invoke(main, ["validate"]) + + assert result.exit_code != 0 + assert "Missing argument" in result.output + + def test_validate_with_nonexistent_file(self): + """Test validate with nonexistent file shows error.""" + result = self.runner.invoke(main, ["validate", "--config", "/nonexistent/file.yaml"]) + + assert result.exit_code != 0