mirror of
https://github.com/zvx-echo6/central.git
synced 2026-05-21 18:14:44 +02:00
test: remove TomlConfigSource and config_source flag tests
TOML-related tests no longer needed after Phase C retirement. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c6f4f3b081
commit
a362b7b93e
2 changed files with 0 additions and 190 deletions
|
|
@ -1,9 +1,7 @@
|
|||
"""Tests for configuration source abstraction."""
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
import asyncpg
|
||||
|
|
@ -12,11 +10,8 @@ import pytest_asyncio
|
|||
|
||||
from central.config_source import (
|
||||
ConfigSource,
|
||||
TomlConfigSource,
|
||||
DbConfigSource,
|
||||
create_config_source,
|
||||
)
|
||||
from central.config_store import ConfigStore
|
||||
from central.crypto import KEY_SIZE, clear_key_cache
|
||||
|
||||
# Test database DSN
|
||||
|
|
@ -43,93 +38,6 @@ def setup_master_key(master_key_path: Path, monkeypatch: pytest.MonkeyPatch) ->
|
|||
monkeypatch.setenv("CENTRAL_MASTER_KEY_PATH", str(master_key_path))
|
||||
|
||||
|
||||
class TestTomlConfigSource:
|
||||
"""Tests for TOML-based config source."""
|
||||
|
||||
@pytest.fixture
|
||||
def toml_file(self, tmp_path: Path) -> Path:
|
||||
"""Create a test TOML config file."""
|
||||
toml_content = """
|
||||
[adapters.nws]
|
||||
enabled = true
|
||||
cadence_s = 60
|
||||
states = ["ID", "MT"]
|
||||
contact_email = "test@example.com"
|
||||
|
||||
[adapters.disabled_adapter]
|
||||
enabled = false
|
||||
cadence_s = 300
|
||||
states = []
|
||||
contact_email = "test@example.com"
|
||||
|
||||
[cloudevents]
|
||||
type_prefix = "central"
|
||||
source = "central.local"
|
||||
schema_version = "1.0"
|
||||
|
||||
[nats]
|
||||
url = "nats://localhost:4222"
|
||||
|
||||
[postgres]
|
||||
dsn = "postgresql://user:pass@localhost/db"
|
||||
"""
|
||||
path = tmp_path / "central.toml"
|
||||
path.write_text(toml_content)
|
||||
return path
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_enabled_adapters(self, toml_file: Path) -> None:
|
||||
"""list_enabled_adapters returns only enabled adapters."""
|
||||
source = TomlConfigSource(toml_file)
|
||||
adapters = await source.list_enabled_adapters()
|
||||
|
||||
assert len(adapters) == 1
|
||||
assert adapters[0].name == "nws"
|
||||
assert adapters[0].enabled is True
|
||||
assert adapters[0].cadence_s == 60
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_adapter(self, toml_file: Path) -> None:
|
||||
"""get_adapter returns correct adapter config."""
|
||||
source = TomlConfigSource(toml_file)
|
||||
|
||||
adapter = await source.get_adapter("nws")
|
||||
assert adapter is not None
|
||||
assert adapter.name == "nws"
|
||||
assert adapter.settings["states"] == ["ID", "MT"]
|
||||
assert adapter.settings["contact_email"] == "test@example.com"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_nonexistent_adapter(self, toml_file: Path) -> None:
|
||||
"""get_adapter returns None for nonexistent adapter."""
|
||||
source = TomlConfigSource(toml_file)
|
||||
adapter = await source.get_adapter("does_not_exist")
|
||||
assert adapter is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_watch_for_changes_returns_immediately(self, toml_file: Path) -> None:
|
||||
"""watch_for_changes is a no-op for TOML source."""
|
||||
source = TomlConfigSource(toml_file)
|
||||
callback_called = False
|
||||
|
||||
async def callback(table: str, key: str) -> None:
|
||||
nonlocal callback_called
|
||||
callback_called = True
|
||||
|
||||
# Should return immediately without blocking
|
||||
await asyncio.wait_for(
|
||||
source.watch_for_changes(callback),
|
||||
timeout=1.0,
|
||||
)
|
||||
assert not callback_called
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_implements_protocol(self, toml_file: Path) -> None:
|
||||
"""TomlConfigSource implements ConfigSource protocol."""
|
||||
source = TomlConfigSource(toml_file)
|
||||
assert isinstance(source, ConfigSource)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def db_conn() -> asyncpg.Connection:
|
||||
"""Get a direct database connection for setup/teardown."""
|
||||
|
|
@ -222,64 +130,3 @@ class TestDbConfigSource:
|
|||
async def test_implements_protocol(self, db_source: DbConfigSource) -> None:
|
||||
"""DbConfigSource implements ConfigSource protocol."""
|
||||
assert isinstance(db_source, ConfigSource)
|
||||
|
||||
|
||||
class TestCreateConfigSource:
|
||||
"""Tests for the config source factory function."""
|
||||
|
||||
@pytest.fixture
|
||||
def toml_file(self, tmp_path: Path) -> Path:
|
||||
"""Create a minimal TOML config file."""
|
||||
toml_content = """
|
||||
[adapters.nws]
|
||||
enabled = true
|
||||
cadence_s = 60
|
||||
states = []
|
||||
contact_email = "test@example.com"
|
||||
|
||||
[cloudevents]
|
||||
[nats]
|
||||
[postgres]
|
||||
dsn = "postgresql://test@localhost/test"
|
||||
"""
|
||||
path = tmp_path / "central.toml"
|
||||
path.write_text(toml_content)
|
||||
return path
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_toml_source(self, toml_file: Path) -> None:
|
||||
"""create_config_source returns TomlConfigSource for 'toml' type."""
|
||||
source = await create_config_source(
|
||||
source_type="toml",
|
||||
toml_path=toml_file,
|
||||
)
|
||||
assert isinstance(source, TomlConfigSource)
|
||||
await source.close()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_db_source(self, clean_config_schema: None) -> None:
|
||||
"""create_config_source returns DbConfigSource for 'db' type."""
|
||||
source = await create_config_source(
|
||||
source_type="db",
|
||||
dsn=TEST_DB_DSN,
|
||||
)
|
||||
assert isinstance(source, DbConfigSource)
|
||||
await source.close()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_toml_requires_path(self) -> None:
|
||||
"""create_config_source raises for 'toml' without path."""
|
||||
with pytest.raises(ValueError, match="toml_path required"):
|
||||
await create_config_source(source_type="toml")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_db_requires_dsn(self) -> None:
|
||||
"""create_config_source raises for 'db' without dsn."""
|
||||
with pytest.raises(ValueError, match="dsn required"):
|
||||
await create_config_source(source_type="db")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_unknown_type_raises(self) -> None:
|
||||
"""create_config_source raises for unknown type."""
|
||||
with pytest.raises(ValueError, match="Unknown config source type"):
|
||||
await create_config_source(source_type="unknown")
|
||||
|
|
|
|||
|
|
@ -355,40 +355,3 @@ class TestRateLimitGuarantee:
|
|||
f"Multiple NOTIFYs should not cause extra polls."
|
||||
)
|
||||
|
||||
|
||||
class TestBootstrapConfigFlag:
|
||||
"""Tests for CENTRAL_CONFIG_SOURCE bootstrap flag."""
|
||||
|
||||
def test_default_is_toml(self) -> None:
|
||||
"""Default config_source is 'toml'."""
|
||||
from central.bootstrap_config import Settings
|
||||
|
||||
# Create settings with minimal required fields
|
||||
settings = Settings(
|
||||
db_dsn="postgresql://test@localhost/test",
|
||||
_env_file=None,
|
||||
)
|
||||
assert settings.config_source == "toml"
|
||||
|
||||
def test_accepts_db(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""config_source accepts 'db' value."""
|
||||
from central.bootstrap_config import Settings, get_settings
|
||||
|
||||
get_settings.cache_clear()
|
||||
monkeypatch.setenv("CENTRAL_CONFIG_SOURCE", "db")
|
||||
monkeypatch.setenv("CENTRAL_DB_DSN", "postgresql://test@localhost/test")
|
||||
|
||||
settings = get_settings()
|
||||
assert settings.config_source == "db"
|
||||
|
||||
def test_rejects_invalid(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""config_source rejects invalid values."""
|
||||
from pydantic import ValidationError
|
||||
from central.bootstrap_config import Settings, get_settings
|
||||
|
||||
get_settings.cache_clear()
|
||||
monkeypatch.setenv("CENTRAL_CONFIG_SOURCE", "invalid")
|
||||
monkeypatch.setenv("CENTRAL_DB_DSN", "postgresql://test@localhost/test")
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
get_settings()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue