35 lines
853 B
Python
35 lines
853 B
Python
"""Tests for config module — _env_int error path."""
|
|
|
|
import os
|
|
from unittest.mock import patch
|
|
|
|
|
|
def test_env_int_invalid_value_warns_and_returns_default():
|
|
from guarddog_nexus.config import _env_int
|
|
|
|
os.environ["TEST_PORT"] = "notanumber"
|
|
|
|
with patch("logging.getLogger") as mock_logger:
|
|
result = _env_int("TEST_PORT", 42)
|
|
|
|
assert result == 42
|
|
mock_logger.return_value.warning.assert_called_once()
|
|
|
|
del os.environ["TEST_PORT"]
|
|
|
|
|
|
def test_env_int_missing_returns_default():
|
|
from guarddog_nexus.config import _env_int
|
|
|
|
os.environ.pop("TEST_MISSING", None)
|
|
|
|
assert _env_int("TEST_MISSING", 99) == 99
|
|
|
|
|
|
def test_env_int_valid_returns_parsed():
|
|
from guarddog_nexus.config import _env_int
|
|
|
|
os.environ["TEST_VALID"] = "8080"
|
|
assert _env_int("TEST_VALID", 42) == 8080
|
|
del os.environ["TEST_VALID"]
|