mirror of
https://github.com/elastic/logstash.git
synced 2025-04-19 04:15:23 -04:00
Work done by @guyboertje and @ph Since JRuby 1.7.25 is now EOL we are migrating Logstash to use JRuby 9k and JDK8 only, Not much needed updating to make this work, its was mostly a drop in replacement from the previous version. The major point was the change in the implementation of Time in JRuby, JRuby now use `java.time` instead of joda time, this allow JRuby to have nanoseconds precision on time object.
61 lines
2.3 KiB
Ruby
61 lines
2.3 KiB
Ruby
# encoding: utf-8
|
|
require "pluginmanager/pack_installer/local"
|
|
require "stud/temporary"
|
|
require "fileutils"
|
|
|
|
describe LogStash::PluginManager::PackInstaller::Local do
|
|
subject { described_class.new(local_file) }
|
|
|
|
context "when the local file doesn't exist" do
|
|
let(:local_file) { ::File.join(Stud::Temporary.pathname, Time.now.to_s.to_s) }
|
|
|
|
it "raises an exception" do
|
|
expect { subject.execute }.to raise_error(LogStash::PluginManager::FileNotFoundError)
|
|
end
|
|
end
|
|
|
|
context "when the local file exist" do
|
|
context "when the file has the wrong extension" do
|
|
let(:local_file) { Stud::Temporary.file.path }
|
|
|
|
it "raises a InvalidPackError" do
|
|
expect { subject.execute }.to raise_error(LogStash::PluginManager::InvalidPackError, /Invalid format/)
|
|
end
|
|
end
|
|
|
|
context "when there is an error when the zip get uncompressed" do
|
|
let(:local_file) do
|
|
directory = Stud::Temporary.pathname
|
|
FileUtils.mkdir_p(directory)
|
|
p = ::File.join(directory, "#{Time.now.to_i.to_s}.zip")
|
|
FileUtils.touch(p)
|
|
p
|
|
end
|
|
|
|
it "raises a InvalidPackError" do
|
|
expect { subject.execute }.to raise_error(LogStash::PluginManager::InvalidPackError, /Cannot uncompress the zip/)
|
|
end
|
|
end
|
|
|
|
context "when the file doesnt have plugins in it" do
|
|
let(:local_file) { ::File.join(::File.dirname(__FILE__), "..", "..", "..", "support", "pack", "empty-pack.zip") }
|
|
|
|
it "raise an Invalid pack" do
|
|
expect { subject.execute }.to raise_error(LogStash::PluginManager::InvalidPackError, /The pack must contains at least one plugin/)
|
|
end
|
|
end
|
|
|
|
context "when the pack is valid" do
|
|
let(:local_file) { ::File.join(::File.dirname(__FILE__), "..", "..", "..", "support", "pack", "valid-pack.zip") }
|
|
|
|
it "install the gems" do
|
|
expect(::Bundler::LogstashInjector).to receive(:inject!).with(be_kind_of(LogStash::PluginManager::PackInstaller::Pack)).and_return([])
|
|
|
|
expect(::LogStash::PluginManager::GemInstaller).to receive(:install).with(/logstash-input-packtest/, anything)
|
|
expect(::LogStash::PluginManager::GemInstaller).to receive(:install).with(/logstash-input-packtestdep/, anything)
|
|
|
|
expect { subject.execute }.not_to raise_error
|
|
end
|
|
end
|
|
end
|
|
end
|