mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
workarround the version check for pre released plugins as looks like rubygems is not activating them by default
Add a pre release gem test by using a mock to reproduce the behaviour reaised by Gem::Specification.find_by_name when dealing with pre release gems. Fixes #3476
This commit is contained in:
parent
a81f0249b1
commit
bd7516108f
2 changed files with 31 additions and 4 deletions
|
@ -22,8 +22,14 @@ module LogStash::Util
|
|||
|
||||
def self.find_version!(name)
|
||||
begin
|
||||
specification = Gem::Specification.find_by_name(name)
|
||||
new(specification.version)
|
||||
spec = Gem::Specification.find_by_name(name)
|
||||
if spec.nil?
|
||||
# Checking for nil? is a workaround for situations where find_by_name
|
||||
# is not able to find the real spec, as for example with pre releases
|
||||
# of plugins
|
||||
spec = Gem::Specification.find_all_by_name(name).first
|
||||
end
|
||||
new(spec.version)
|
||||
rescue Gem::LoadError
|
||||
# Rescuing the LoadError and raise a Logstash specific error.
|
||||
# Likely we can't find the gem in the current GEM_PATH
|
||||
|
@ -39,5 +45,11 @@ module LogStash::Util
|
|||
def <=>(other)
|
||||
version <=> other.version
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.build_from_spec(spec)
|
||||
new(spec.version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,18 +1,33 @@
|
|||
require "spec_helper"
|
||||
require "logstash/util/plugin_version"
|
||||
|
||||
describe LogStash::Util::PluginVersion do
|
||||
describe "LogStash::Util::PluginVersion" do
|
||||
|
||||
subject { LogStash::Util::PluginVersion }
|
||||
|
||||
context "#find_version!" do
|
||||
|
||||
let(:gem) { "bundler" }
|
||||
|
||||
it 'raises an PluginNoVersionError if we cant find the plugin in the gem path' do
|
||||
dummy_name ='this-character-doesnt-exist-in-the-marvel-universe'
|
||||
expect { subject.find_version!(dummy_name) }.to raise_error(LogStash::PluginNoVersionError)
|
||||
end
|
||||
|
||||
it 'returns the version of the gem' do
|
||||
expect { subject.find_version!('bundler') }.not_to raise_error
|
||||
expect { subject.find_version!(gem) }.not_to raise_error
|
||||
end
|
||||
|
||||
context "with a pre release gem" do
|
||||
|
||||
it 'return the version of the gem' do
|
||||
# Gem::Specification.find_by_name return nil if the gem is not activated, as for
|
||||
# example the pre release ones.
|
||||
expect(Gem::Specification).to receive(:find_by_name).and_return(nil)
|
||||
expect { subject.find_version!(gem) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "#new" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue