Files
SnarfCode/tests/unit/test_plugin_base.py
2026-05-22 00:19:30 -04:00

75 lines
2.5 KiB
Python

"""Unit tests for the ProviderPlugin abstract base class."""
import pytest
from iac_reverse.models import (
CpuArchitecture,
PlatformCategory,
ScanProgress,
ScanResult,
)
from iac_reverse.plugin_base import ProviderPlugin
class TestProviderPluginInterface:
def test_cannot_instantiate_directly(self):
"""ProviderPlugin is abstract and cannot be instantiated."""
with pytest.raises(TypeError):
ProviderPlugin()
def test_requires_all_abstract_methods(self):
"""A subclass must implement all abstract methods."""
class IncompletePlugin(ProviderPlugin):
def authenticate(self, credentials):
pass
with pytest.raises(TypeError):
IncompletePlugin()
def test_concrete_implementation(self):
"""A complete implementation can be instantiated."""
class ConcretePlugin(ProviderPlugin):
def authenticate(self, credentials: dict[str, str]) -> None:
pass
def get_platform_category(self) -> PlatformCategory:
return PlatformCategory.CONTAINER_ORCHESTRATION
def list_endpoints(self) -> list[str]:
return ["https://localhost:6443"]
def list_supported_resource_types(self) -> list[str]:
return ["kubernetes_deployment"]
def detect_architecture(self, endpoint: str) -> CpuArchitecture:
return CpuArchitecture.AMD64
def discover_resources(self, endpoints, resource_types, progress_callback):
return ScanResult(
resources=[],
warnings=[],
errors=[],
scan_timestamp="2024-01-01T00:00:00Z",
profile_hash="test",
)
plugin = ConcretePlugin()
assert plugin.get_platform_category() == PlatformCategory.CONTAINER_ORCHESTRATION
assert plugin.list_endpoints() == ["https://localhost:6443"]
assert plugin.list_supported_resource_types() == ["kubernetes_deployment"]
assert plugin.detect_architecture("localhost") == CpuArchitecture.AMD64
def test_abstract_methods_list(self):
"""Verify all expected abstract methods are defined."""
expected_methods = {
"authenticate",
"get_platform_category",
"list_endpoints",
"list_supported_resource_types",
"detect_architecture",
"discover_resources",
}
assert ProviderPlugin.__abstractmethods__ == expected_methods