Add remove method for LogStash::PLUGIN_REGISTRY

Fixes #8378
This commit is contained in:
liketic 2017-09-23 17:45:16 +08:00 committed by Andrew Cholakian
parent 5a9e670c4b
commit 1231d72823
2 changed files with 11 additions and 0 deletions

View file

@ -202,6 +202,10 @@ module LogStash module Plugins
add_plugin(type, name, klass)
end
def remove(type, plugin_name)
@registry.delete(key_for(type, plugin_name))
end
def get(type, plugin_name)
@registry[key_for(type, plugin_name)]
end

View file

@ -61,6 +61,13 @@ describe LogStash::Plugins::Registry do
expect(registry.lookup("filter", "simple_plugin")).to eq(simple_plugin)
end
it "should plugin been removed" do
registry.add(:filter, "simple_plugin", simple_plugin)
expect(registry.lookup("filter", "simple_plugin")).to eq(simple_plugin)
registry.remove(:filter, "simple_plugin")
expect { registry.lookup("filter", "simple_plugin") }.to raise_error(LoadError)
end
it "doesn't add multiple time the same plugin" do
plugin1 = Class.new
plugin2 = Class.new