Load MINIO_SECURE from env and replace adapter asserts with explicit errors.
Default TLS to enabled for production MinIO setups while keeping local and integration tests on plain HTTP via explicit secure=false configuration. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
co-authored by
Cursor
parent
7991dabdbc
commit
3aa91280ec
@@ -7,17 +7,59 @@ import pytest
|
||||
from python_repositories.config import MinioConfig
|
||||
|
||||
|
||||
def test_from_env_loads_all_fields(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def _set_required_minio_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("MINIO_ENDPOINT", "localhost:9000")
|
||||
monkeypatch.setenv("MINIO_ACCESS_KEY", "access")
|
||||
monkeypatch.setenv("MINIO_SECRET_KEY", "secret")
|
||||
monkeypatch.setenv("MINIO_BUCKET", "my-bucket")
|
||||
|
||||
|
||||
def test_from_env_loads_all_fields(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
_set_required_minio_env(monkeypatch)
|
||||
config = MinioConfig.from_env(use_dotenv=False)
|
||||
assert config.endpoint == "localhost:9000"
|
||||
assert config.access_key == "access"
|
||||
assert config.secret_key == "secret"
|
||||
assert config.bucket == "my-bucket"
|
||||
assert config.secure is False
|
||||
assert config.secure is True
|
||||
|
||||
|
||||
def test_from_env_defaults_secure_to_true_when_unset(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
_set_required_minio_env(monkeypatch)
|
||||
monkeypatch.delenv("MINIO_SECURE", raising=False)
|
||||
config = MinioConfig.from_env(use_dotenv=False)
|
||||
assert config.secure is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected"),
|
||||
[
|
||||
("true", True),
|
||||
("1", True),
|
||||
("yes", True),
|
||||
("false", False),
|
||||
("0", False),
|
||||
("no", False),
|
||||
],
|
||||
)
|
||||
def test_from_env_parses_secure(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
value: str,
|
||||
expected: bool,
|
||||
) -> None:
|
||||
_set_required_minio_env(monkeypatch)
|
||||
monkeypatch.setenv("MINIO_SECURE", value)
|
||||
config = MinioConfig.from_env(use_dotenv=False)
|
||||
assert config.secure is expected
|
||||
|
||||
|
||||
def test_from_env_raises_for_invalid_secure(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
_set_required_minio_env(monkeypatch)
|
||||
monkeypatch.setenv("MINIO_SECURE", "not-a-bool")
|
||||
with pytest.raises(ValueError, match="MINIO_SECURE"):
|
||||
MinioConfig.from_env(use_dotenv=False)
|
||||
|
||||
|
||||
def test_from_env_raises_when_endpoint_missing(
|
||||
|
||||
Reference in New Issue
Block a user