test: add discovery tests proving end-to-end plugin loading
This commit is contained in:
parent
b98171c3b8
commit
a4e6a536cf
@ -22,7 +22,7 @@ def discover_plugins(
|
|||||||
logger.warning("Plugin package '%s' not found, skipping", package)
|
logger.warning("Plugin package '%s' not found, skipping", package)
|
||||||
return
|
return
|
||||||
|
|
||||||
if hasattr(mod, "__path__"):
|
if not hasattr(mod, "__path__"):
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Plugin package '%s' has no __path__ attribute, skipping", package
|
"Plugin package '%s' has no __path__ attribute, skipping", package
|
||||||
)
|
)
|
||||||
|
|||||||
40
tests/unit/test_plugin_discovery.py
Normal file
40
tests/unit/test_plugin_discovery.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
from proxy_pool.config import Settings, DatabaseSettings
|
||||||
|
from proxy_pool.plugins.discovery import discover_plugins
|
||||||
|
from proxy_pool.plugins.registry import PluginRegistry
|
||||||
|
|
||||||
|
|
||||||
|
def test_discovers_builtin_parsers():
|
||||||
|
settings = Settings(
|
||||||
|
secret_key="test",
|
||||||
|
db=DatabaseSettings(url="postgresql+asyncpg://localhost/test"),
|
||||||
|
)
|
||||||
|
registry = PluginRegistry()
|
||||||
|
|
||||||
|
discover_plugins("proxy_pool.plugins.builtin.parsers", registry, settings)
|
||||||
|
|
||||||
|
assert "plaintext" in registry.parsers
|
||||||
|
|
||||||
|
|
||||||
|
def test_discovers_builtin_checkers():
|
||||||
|
settings = Settings(
|
||||||
|
secret_key="test",
|
||||||
|
db=DatabaseSettings(url="postgresql+asyncpg://localhost/test"),
|
||||||
|
)
|
||||||
|
registry = PluginRegistry()
|
||||||
|
|
||||||
|
discover_plugins("proxy_pool.plugins.builtin.checkers", registry, settings)
|
||||||
|
|
||||||
|
assert len(registry.checkers) > 0
|
||||||
|
assert registry.checkers[0].name == "tcp_connect"
|
||||||
|
|
||||||
|
|
||||||
|
def test_skips_unconfigured_notifiers():
|
||||||
|
settings = Settings(
|
||||||
|
secret_key="test",
|
||||||
|
db=DatabaseSettings(url="postgresql+asyncpg://localhost/test"),
|
||||||
|
)
|
||||||
|
registry = PluginRegistry()
|
||||||
|
|
||||||
|
discover_plugins("proxy_pool.plugins.builtin.notifiers", registry, settings)
|
||||||
|
|
||||||
|
assert len(registry.notifiers) == 0
|
||||||
Loading…
x
Reference in New Issue
Block a user