99 lines
2.4 KiB
Python
99 lines
2.4 KiB
Python
"""Pytest configuration and fixtures for confgen tests."""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
from typing import Generator
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_project_dir() -> Generator[Path, None, None]:
|
|
"""Create a temporary directory for testing."""
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
yield Path(tmp_dir)
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_template(temp_project_dir: Path) -> Path:
|
|
"""Create a sample template file."""
|
|
template_content = """
|
|
app_name: {{APP_NAME}}
|
|
version: {{VERSION}}
|
|
database:
|
|
host: {{DB_HOST}}
|
|
port: {{DB_PORT}}
|
|
"""
|
|
template_path = temp_project_dir / "template.yaml.j2"
|
|
template_path.write_text(template_content)
|
|
return template_path
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_config(temp_project_dir: Path) -> Path:
|
|
"""Create a sample configuration file."""
|
|
config_content = """
|
|
app_name: myapp
|
|
version: 1.0.0
|
|
database:
|
|
host: localhost
|
|
port: 5432
|
|
"""
|
|
config_path = temp_project_dir / "config.yaml"
|
|
config_path.write_text(config_content)
|
|
return config_path
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_schema(temp_project_dir: Path) -> Path:
|
|
"""Create a sample JSON schema."""
|
|
import json
|
|
|
|
schema_content = {
|
|
"type": "object",
|
|
"properties": {
|
|
"app_name": {"type": "string"},
|
|
"version": {"type": "string"},
|
|
"database": {
|
|
"type": "object",
|
|
"properties": {
|
|
"host": {"type": "string"},
|
|
"port": {"type": "integer", "minimum": 1, "maximum": 65535},
|
|
},
|
|
"required": ["host", "port"],
|
|
},
|
|
},
|
|
"required": ["app_name", "database"],
|
|
}
|
|
schema_path = temp_project_dir / "schema.json"
|
|
schema_path.write_text(json.dumps(schema_content))
|
|
return schema_path
|
|
|
|
|
|
@pytest.fixture
|
|
def confgen_config(temp_project_dir: Path) -> Path:
|
|
"""Create a sample confgen.yaml configuration."""
|
|
config_content = """
|
|
templates:
|
|
sample:
|
|
path: template.yaml.j2
|
|
format: yaml
|
|
|
|
environments:
|
|
dev:
|
|
variables:
|
|
APP_NAME: myapp-dev
|
|
VERSION: 1.0.0-dev
|
|
DB_HOST: localhost
|
|
DB_PORT: 5432
|
|
prod:
|
|
variables:
|
|
APP_NAME: myapp
|
|
VERSION: 1.0.0
|
|
DB_HOST: db.example.com
|
|
DB_PORT: 5432
|
|
"""
|
|
config_path = temp_project_dir / "confgen.yaml"
|
|
config_path.write_text(config_content)
|
|
return config_path
|