#include #include #include #include #include "Configurable.hpp" #include #include using namespace Void::Plugin; #if defined(VOID_CONFIGURABLE_PATH) && __has_include() namespace { VoidTest::IConfigurable* configurable(const PluginHandle& h) { return VoidTest::as_configurable(h.get()); } } // namespace Void::Testing::Test configure_called_with_provider_payload_before_on_load() { PluginManager mgr{{.config_provider = [](std::string_view name) { return std::string{"{\"plugin\":\""} + std::string{name} + "\"}"; }}}; const auto name = mgr.load(VOID_CONFIGURABLE_PATH); Void::Testing::expect(name.has_value()); auto h = mgr.acquire("ConfigurablePlugin"); Void::Testing::expect_eq(configurable(h)->configure_calls(), 1); Void::Testing::expect(configurable(h)->configured_before_on_load()); Void::Testing::expect_eq( configurable(h)->last_config(), std::string_view{"{\"plugin\":\"ConfigurablePlugin\"}"}); } Void::Testing::Test configure_reruns_on_reload_with_fresh_payload() { Void::FileSystem::TempDir tmp{"void_cfg"}; const auto so = tmp.path() / "plugin.so"; std::filesystem::copy_file(VOID_CONFIGURABLE_PATH, so); int generation = 0; PluginManager mgr{{.config_provider = [&generation](std::string_view) { return std::string{"gen="} + std::to_string(generation); }}}; Void::Testing::expect(mgr.load(so).has_value()); generation = 1; Void::Testing::expect(mgr.reload("ConfigurablePlugin").has_value()); auto h = mgr.acquire("ConfigurablePlugin"); // The reloaded instance is fresh: one configure call, new payload. Void::Testing::expect_eq(configurable(h)->configure_calls(), 1); Void::Testing::expect_eq(configurable(h)->last_config(), std::string_view{"gen=1"}); Void::Testing::expect(configurable(h)->configured_before_on_load()); } Void::Testing::Test configure_skipped_without_provider() { PluginManager mgr; Void::Testing::expect(mgr.load(VOID_CONFIGURABLE_PATH).has_value()); auto h = mgr.acquire("ConfigurablePlugin"); Void::Testing::expect_eq(configurable(h)->configure_calls(), 0); } #endif // configurable plugin available