feat(cloud): validate control plane and host configuration
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from host_agent.config import (
|
||||
HostAgentConfigurationError,
|
||||
HostAgentConfig,
|
||||
load_host_agent_config,
|
||||
)
|
||||
|
||||
|
||||
BASE_ENV = {
|
||||
"HOST_AGENT_HOST_ID": "host-a",
|
||||
"HOST_AGENT_TOKEN": "secret",
|
||||
}
|
||||
|
||||
|
||||
def test_load_host_agent_config_uses_local_network_defaults() -> None:
|
||||
assert load_host_agent_config(BASE_ENV) == HostAgentConfig(
|
||||
control_plane_url="http://127.0.0.1:8001",
|
||||
host_id="host-a",
|
||||
token="secret",
|
||||
)
|
||||
|
||||
|
||||
def test_load_host_agent_config_parses_poll_and_retry_values() -> None:
|
||||
config = load_host_agent_config(
|
||||
{
|
||||
**BASE_ENV,
|
||||
"HOST_AGENT_CONTROL_PLANE_URL": "https://cloud.example/v1/",
|
||||
"HOST_AGENT_HEARTBEAT_INTERVAL_SECONDS": "10",
|
||||
"HOST_AGENT_POLL_TIMEOUT_SECONDS": "15",
|
||||
"HOST_AGENT_RETRY_BACKOFF_SECONDS": "2",
|
||||
"HOST_AGENT_MAX_RETRY_BACKOFF_SECONDS": "20",
|
||||
}
|
||||
)
|
||||
|
||||
assert config.control_plane_url == "https://cloud.example/v1"
|
||||
assert config.poll_timeout_seconds == 15
|
||||
assert config.max_retry_backoff_seconds == 20
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"overrides",
|
||||
[
|
||||
{"HOST_AGENT_HOST_ID": ""},
|
||||
{"HOST_AGENT_TOKEN": ""},
|
||||
{"HOST_AGENT_CONTROL_PLANE_URL": "ftp://cloud.example"},
|
||||
{"HOST_AGENT_POLL_TIMEOUT_SECONDS": "0"},
|
||||
{
|
||||
"HOST_AGENT_RETRY_BACKOFF_SECONDS": "10",
|
||||
"HOST_AGENT_MAX_RETRY_BACKOFF_SECONDS": "5",
|
||||
},
|
||||
],
|
||||
)
|
||||
def test_load_host_agent_config_rejects_invalid_values(
|
||||
overrides: dict[str, str],
|
||||
) -> None:
|
||||
with pytest.raises(HostAgentConfigurationError):
|
||||
load_host_agent_config({**BASE_ENV, **overrides})
|
||||
Reference in New Issue
Block a user