From 99d63180e6f241349b51e5bdc1f368f137bc90c9 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 22 Mar 2026 15:14:08 +0000 Subject: [PATCH] Initial upload: EnvSchema v0.1.0 with CI/CD workflow --- tests/integration/test_full_flow.py | 113 ++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/integration/test_full_flow.py diff --git a/tests/integration/test_full_flow.py b/tests/integration/test_full_flow.py new file mode 100644 index 0000000..65ac1b1 --- /dev/null +++ b/tests/integration/test_full_flow.py @@ -0,0 +1,113 @@ +"""End-to-end integration tests.""" + +import json +import tempfile +from pathlib import Path + +import pytest +from click.testing import CliRunner + +from envschema.cli import cli + + +class TestFullFlow: + """Tests for complete validation flows.""" + + def test_create_schema_validate_env(self, tmp_path): + schema_file = tmp_path / "schema.json" + schema_content = { + "version": "1.0", + "envVars": [ + { + "name": "DATABASE_URL", + "type": "str", + "required": True, + "description": "Database connection string" + }, + { + "name": "DEBUG_MODE", + "type": "bool", + "required": False, + "default": "false" + }, + { + "name": "MAX_CONNECTIONS", + "type": "int", + "required": False, + "default": "10" + } + ] + } + schema_file.write_text(json.dumps(schema_content)) + + env_file = tmp_path / ".env" + env_file.write_text('DATABASE_URL=postgres://localhost/mydb\nDEBUG_MODE=true\n') + + runner = CliRunner() + result = runner.invoke(cli, [ + "validate", + str(schema_file), + "--file", str(env_file), + "--no-env" + ]) + assert result.exit_code == 0 + + def test_validation_fails_on_type_error(self, tmp_path): + schema_file = tmp_path / "schema.json" + schema_file.write_text(json.dumps({ + "version": "1.0", + "envVars": [ + {"name": "MAX_CONNECTIONS", "type": "int"} + ] + })) + + env_file = tmp_path / ".env" + env_file.write_text('MAX_CONNECTIONS=not_a_number\n') + + runner = CliRunner() + result = runner.invoke(cli, [ + "validate", + str(schema_file), + "--file", str(env_file), + "--no-env" + ]) + assert result.exit_code == 1 + + def test_generate_and_validate(self, tmp_path): + schema_file = tmp_path / "schema.json" + schema_file.write_text(json.dumps({ + "version": "1.0", + "envVars": [ + {"name": "NEW_VAR", "type": "str", "required": True} + ] + })) + + output_file = tmp_path / ".env.example" + runner = CliRunner() + result = runner.invoke(cli, ["generate", str(schema_file), "--output", str(output_file)]) + assert result.exit_code == 0 + + content = output_file.read_text() + assert "NEW_VAR=" in content + + def test_ci_mode_output(self, tmp_path): + schema_file = tmp_path / "schema.json" + schema_file.write_text(json.dumps({ + "version": "1.0", + "envVars": [ + {"name": "TEST_VAR", "type": "str", "required": True} + ] + })) + env_file = tmp_path / ".env" + env_file.write_text('TEST_VAR=value\n') + + runner = CliRunner() + result = runner.invoke(cli, [ + "validate", + str(schema_file), + "--file", str(env_file), + "--no-env", + "--ci" + ]) + assert result.exit_code == 0 + assert "Validation passed" in result.output \ No newline at end of file