- Refactored HAProxy configuration files, templates, and paths to use `/etc/easyhaproxy` instead of `/etc/haproxy`. - Updated Dockerfile to generate DH params and placeholder certificates in the new configuration directory. - Added health check support with timeout to `DockerComposeFixture` in E2E test utilities. - Adjusted tests, templates, and plugins to use the new `Consts`-based configuration paths. - Introduced pytest fixtures for environment isolation and temporary directory management.
43 lines
No EOL
1.1 KiB
Python
43 lines
No EOL
1.1 KiB
Python
"""
|
|
Pytest configuration and fixtures for EasyHAProxy tests.
|
|
|
|
This module provides session-wide and function-level fixtures for testing.
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
import tempfile
|
|
import pytest
|
|
|
|
|
|
# Create a session-wide temporary directory for all tests
|
|
# Use a different prefix to avoid conflicts with cleanup plugin (which looks for "easyhaproxy_*")
|
|
_test_session_dir = tempfile.mkdtemp(prefix="pytest_easyhaproxy_")
|
|
os.environ["EASYHAPROXY_BASE_PATH"] = _test_session_dir
|
|
|
|
|
|
@pytest.fixture(scope="function", autouse=True)
|
|
def reset_consts():
|
|
"""
|
|
Reset Consts before and after each test.
|
|
|
|
This ensures:
|
|
1. Each test picks up the EASYHAPROXY_BASE_PATH environment variable
|
|
2. Tests don't get permission errors trying to write to /etc/easyhaproxy/
|
|
3. Consts path cache is cleared between tests for isolation
|
|
"""
|
|
from functions import Consts
|
|
Consts.reset()
|
|
yield
|
|
Consts.reset()
|
|
|
|
|
|
def pytest_sessionfinish(session, exitstatus):
|
|
"""
|
|
Cleanup session temporary directory after all tests complete.
|
|
"""
|
|
try:
|
|
shutil.rmtree(_test_session_dir)
|
|
except Exception:
|
|
# Ignore cleanup errors
|
|
pass |