adjust the specs

Fixes #6109
This commit is contained in:
Pier-Hugues Pellerin 2016-10-21 14:12:56 -04:00
parent 58ccca7028
commit 3a652a3076
4 changed files with 32 additions and 24 deletions

View file

@ -132,12 +132,18 @@ module LogStash module Plugins
def lookup(type, plugin_name, &block)
plugin = get(type, plugin_name)
# Assume that we have a legacy plugin
if plugin.nil?
begin
path = "logstash/#{type}s/#{plugin_name}"
require path rescue LoadError # Plugin might be already defined in the current scope
begin
require path
rescue LoadError
# Plugin might be already defined in the current scope
# This scenario often happen in test when we write an adhoc class
end
klass = namespace_lookup(type, plugin_name)
plugin = lazy_add(type, plugin_name, klass)
rescue => e

View file

@ -411,7 +411,7 @@ describe LogStash::Agent do
# We need to create theses dummy classes to know how many
# events where actually generated by the pipeline and successfully send to the output.
# Theses values are compared with what we store in the metric store.
class DummyOutput2 < DummyOutput; end
class DummyOutput2 < LogStash::Outputs::DummyOutput; end
let!(:dummy_output) { DummyOutput.new }
let!(:dummy_output2) { DummyOutput2.new }

View file

@ -31,21 +31,10 @@ describe LogStash::Plugin do
class LogStash::Filters::LadyGaga < LogStash::Filters::Base
config_name "lady_gaga"
end
expect(LogStash::Plugin.lookup("filter", "lady_gaga")).to eq(LogStash::Filters::LadyGaga)
end
describe "plugin signup in the registry" do
let(:registry) { LogStash::PluginRegistry }
it "should be present in the registry" do
class LogStash::Filters::MyPlugin < LogStash::Filters::Base
config_name "my_plugin"
end
expect(registry.exists?(:filter, "my_plugin")).to eq(true)
end
end
describe "#inspect" do
class LogStash::Filters::MyTestFilter < LogStash::Filters::Base
config_name "param1"

View file

@ -10,6 +10,13 @@ class LogStash::Inputs::Dummy < LogStash::Inputs::Base
def register; end
end
class LogStash::Inputs::NewPlugin < LogStash::Inputs::Base
config_name "new_plugin"
def register; end
end
describe LogStash::Plugins::Registry do
let(:registry) { described_class.new }
@ -22,18 +29,13 @@ describe LogStash::Plugins::Registry do
end
it "should raise an error if can not find the plugin class" do
expect(LogStash::Registry::Plugin).to receive(:new).with("input", "elastic").and_return(plugin)
expect(plugin).to receive(:path).and_return("logstash/input/elastic").twice
expect(plugin).to receive(:installed?).and_return(true)
expect { registry.lookup("input", "elastic") }.to raise_error(LoadError)
expect { registry.lookup("input", "do-not-exist-elastic") }.to raise_error(LoadError)
end
it "should load from registry is already load" do
registry.lookup("input", "stdin")
expect(registry).to receive(:registered?).and_return(true).once
registry.lookup("input", "stdin")
internal_registry = registry.instance_variable_get("@registry")
expect(internal_registry).to include("logstash/inputs/stdin" => LogStash::Inputs::Stdin)
expect(registry.exists?(:input, "stdin")).to be_falsey
expect { registry.lookup("input", "new_plugin") }.to change { registry.size }.by(1)
expect { registry.lookup("input", "new_plugin") }.not_to change { registry.size }
end
end
@ -49,4 +51,15 @@ describe LogStash::Plugins::Registry do
expect { registry.lookup("input", "elastic") }.to raise_error(LoadError)
end
end
context "when loading plugin manually configured" do
it "should return the plugin" do
class SimplePlugin
end
expect { registry.lookup("filter", "simple_plugin") }.to raise_error(LoadError)
registry.add(:filter, "simple_plugin", SimplePlugin)
expect(registry.lookup("filter", "simple_plugin")).to eq(SimplePlugin)
end
end
end