Initial upload: EnvSchema v0.1.0 with CI/CD workflow
Some checks failed
CI / test (push) Failing after 16s
Some checks failed
CI / test (push) Failing after 16s
This commit is contained in:
113
tests/integration/test_full_flow.py
Normal file
113
tests/integration/test_full_flow.py
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user