"""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