Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Commit

Permalink
Do not try to reach the artifact server when no plugins is given
Browse files Browse the repository at this point in the history
This PR fix an annoyance when running the `bin/logstash-plugin install
--no-verify` without any plugins, the command was making an unnecessary
call to the artifacts web server.

Fixes elastic#6826
  • Loading branch information
ph authored and suyograo committed Mar 27, 2017
1 parent 918f2ba commit c98b4ee
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
7 changes: 5 additions & 2 deletions lib/pluginmanager/install_strategy_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class InstallStrategyFactory
LogStash::PluginManager::PackFetchStrategy::Repository
]

def self.create(plugins_arg)
def self.create(plugins_args)
plugin_name_or_uri = plugins_args.first
return false if plugin_name_or_uri.nil? || plugin_name_or_uri.strip.empty?

AVAILABLES_STRATEGIES.each do |strategy|
if installer = strategy.get_installer_for(plugins_arg.first)
if installer = strategy.get_installer_for(plugin_name_or_uri)
return installer
end
end
Expand Down
9 changes: 1 addition & 8 deletions spec/unit/plugin_manager/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@
let(:cmd) { LogStash::PluginManager::Install.new("install") }

context "when validating plugins" do
before(:each) do
expect(cmd).to receive(:validate_cli_options!).and_return(nil)
end

before do
expect(LogStash::PluginManager::PackFetchStrategy::Repository).to receive(:get_installer_for).with(anything).and_return(nil)
end

let(:sources) { ["https://rubygems.org", "http://localhost:9292"] }

before(:each) do
expect(cmd).to receive(:validate_cli_options!).and_return(nil)
expect(cmd).to receive(:plugins_gems).and_return([["dummy", nil]])
expect(cmd).to receive(:install_gems_list!).and_return(nil)
expect(cmd).to receive(:remove_unused_locally_installed_gems!).and_return(nil)
Expand Down
49 changes: 35 additions & 14 deletions spec/unit/plugin_manager/install_strategy_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,46 @@

describe LogStash::PluginManager::InstallStrategyFactory do
subject { described_class }
let(:plugins_args) { [ "logstash-pack-mega" ] }

it "returns the first matched strategy" do
success = double("urifetch success")
context "when the plugins args is valid" do
let(:plugins_args) { [ "logstash-pack-mega" ] }

expect(LogStash::PluginManager::PackFetchStrategy::Uri).to receive(:get_installer_for).with(plugins_args.first).and_return(success)
expect(subject.create(plugins_args)).to eq(success)
end
it "returns the first matched strategy" do
success = double("urifetch success")

expect(LogStash::PluginManager::PackFetchStrategy::Uri).to receive(:get_installer_for).with(plugins_args.first).and_return(success)
expect(subject.create(plugins_args)).to eq(success)
end

it "returns the matched strategy" do
success = double("elastic xpack success")

it "returns the matched strategy" do
success = double("elastic xpack success")
expect(LogStash::PluginManager::PackFetchStrategy::Repository).to receive(:get_installer_for).with(plugins_args.first).and_return(success)
expect(subject.create(plugins_args)).to eq(success)
end

expect(LogStash::PluginManager::PackFetchStrategy::Repository).to receive(:get_installer_for).with(plugins_args.first).and_return(success)
expect(subject.create(plugins_args)).to eq(success)
it "return nil when no strategy matches" do
expect(LogStash::PluginManager::PackFetchStrategy::Uri).to receive(:get_installer_for).with(plugins_args.first).and_return(nil)
expect(LogStash::PluginManager::PackFetchStrategy::Repository).to receive(:get_installer_for).with(plugins_args.first).and_return(nil)
expect(subject.create(plugins_args)).to be_falsey
end
end

it "return nil when no strategy matches" do
expect(LogStash::PluginManager::PackFetchStrategy::Uri).to receive(:get_installer_for).with(plugins_args.first).and_return(nil)
expect(LogStash::PluginManager::PackFetchStrategy::Repository).to receive(:get_installer_for).with(plugins_args.first).and_return(nil)
expect(subject.create(plugins_args)).to be_falsey
context "when the plugins args" do
context "is an empty string" do
let(:plugins_args) { [""] }

it "returns no strategy matched" do
expect(subject.create(plugins_args)).to be_falsey
end
end

context "is nil" do
let(:plugins_args) { [] }

it "returns no strategy matched" do
expect(subject.create(plugins_args)).to be_falsey
end
end
end
end

0 comments on commit c98b4ee

Please sign in to comment.