feat: inventory storage infrastructure dependencies
Module Package Release / publish-packages (push) Successful in 12s
Module Package Release / publish-packages (push) Successful in 12s
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
from govoplan_core.core.configuration_packages import (
|
||||
ConfigurationPackageFragment,
|
||||
ConfigurationPreflightContext,
|
||||
@@ -10,10 +14,14 @@ from govoplan_core.core.configuration_packages import (
|
||||
from govoplan_core.core.infrastructure_capabilities import (
|
||||
infrastructure_capability_receipt_from_mapping,
|
||||
)
|
||||
from govoplan_core.db.base import Base
|
||||
from govoplan_core.db.session import configure_database, reset_database
|
||||
from govoplan_files.backend.configuration_provider import (
|
||||
FILES_CONFIGURATION_CAPABILITY,
|
||||
FILES_INFRASTRUCTURE_DEPENDENCY_CAPABILITY,
|
||||
FilesConfigurationProvider,
|
||||
)
|
||||
from govoplan_files.backend.db.models import FileBlob
|
||||
from govoplan_files.backend.manifest import manifest
|
||||
|
||||
|
||||
@@ -78,6 +86,67 @@ def _s3_settings(**overrides):
|
||||
class FilesConfigurationProviderTests(unittest.TestCase):
|
||||
def test_provider_is_registered(self) -> None:
|
||||
self.assertIn(FILES_CONFIGURATION_CAPABILITY, manifest.capability_factories)
|
||||
self.assertIn(
|
||||
FILES_INFRASTRUCTURE_DEPENDENCY_CAPABILITY,
|
||||
manifest.capability_factories,
|
||||
)
|
||||
|
||||
def test_inventory_reports_runtime_binding_and_persisted_blob_aggregate(self) -> None:
|
||||
with tempfile.TemporaryDirectory(prefix="govoplan-files-inventory-") as root:
|
||||
database_path = Path(root) / "files.sqlite3"
|
||||
engine = create_engine(f"sqlite:///{database_path}")
|
||||
Base.metadata.create_all(engine, tables=(FileBlob.__table__,))
|
||||
configure_database(
|
||||
f"sqlite:///{database_path}",
|
||||
engine=engine,
|
||||
dispose_previous=True,
|
||||
)
|
||||
try:
|
||||
with engine.begin() as connection:
|
||||
connection.execute(
|
||||
FileBlob.__table__.insert(),
|
||||
[
|
||||
{
|
||||
"id": "blob-1",
|
||||
"tenant_id": "tenant-1",
|
||||
"storage_backend": "local",
|
||||
"storage_key": "tenant-1/a",
|
||||
"checksum_sha256": "a" * 64,
|
||||
"size_bytes": 7,
|
||||
"protection_discriminator": "plaintext",
|
||||
"ref_count": 1,
|
||||
"integrity_status": "unchecked",
|
||||
},
|
||||
{
|
||||
"id": "blob-2",
|
||||
"tenant_id": "tenant-1",
|
||||
"storage_backend": "local",
|
||||
"storage_key": "tenant-1/b",
|
||||
"checksum_sha256": "b" * 64,
|
||||
"size_bytes": 11,
|
||||
"protection_discriminator": "plaintext",
|
||||
"ref_count": 1,
|
||||
"integrity_status": "unchecked",
|
||||
},
|
||||
],
|
||||
)
|
||||
provider = FilesConfigurationProvider(
|
||||
settings=_local_settings(),
|
||||
environment={},
|
||||
)
|
||||
|
||||
dependencies = provider.infrastructure_dependencies()
|
||||
finally:
|
||||
reset_database()
|
||||
engine.dispose()
|
||||
|
||||
self.assertEqual(
|
||||
["runtime_storage_binding", "stored_blob_set"],
|
||||
[item.dependency_type for item in dependencies],
|
||||
)
|
||||
blob_set = dependencies[1]
|
||||
self.assertEqual(2, blob_set.metrics["blob_count"])
|
||||
self.assertEqual(18, blob_set.metrics["content_bytes"])
|
||||
|
||||
def test_matching_local_storage_is_an_idempotent_noop(self) -> None:
|
||||
provider = FilesConfigurationProvider(
|
||||
|
||||
Reference in New Issue
Block a user