Merge pull request #10154 from chrisroberts/f-local-plugin-prompt

Fix local plugin prompt and add coverage
This commit is contained in:
Chris Roberts 2018-08-30 11:29:00 -07:00 committed by GitHub
commit 9204e41d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 1 deletions

View File

@ -943,7 +943,7 @@ module Vagrant
answer = nil answer = nil
until ["y", "n"].include?(answer) until ["y", "n"].include?(answer)
answer = ui.ask(I18n.t("vagrant.plugins.local.request_plugin_install") + " [N]: ") answer = ui.ask(I18n.t("vagrant.plugins.local.request_plugin_install") + " [N]: ")
answer.strip!.downcase! answer = answer.strip.downcase
answer = "n" if answer.to_s.empty? answer = "n" if answer.to_s.empty?
end end
if answer == "n" if answer == "n"

View File

@ -1430,4 +1430,77 @@ VF
expect(env.machine_names).to eq([:foo, :bar]) expect(env.machine_names).to eq([:foo, :bar])
end end
end end
describe "#process_configured_plugins" do
let(:env) do
isolated_environment.tap do |e|
e.box3("base", "1.0", :virtualbox)
e.vagrantfile(vagrantfile)
end
end
let(:vagrantfile) do
'Vagrant.configure("2"){ |config| config.vm.box = "base" }'
end
let(:plugin_manager) {
double("plugin_manager", installed_plugins: installed_plugins, local_file: local_file)
}
let(:installed_plugins) { {} }
let(:local_file) { double("local_file", installed_plugins: local_installed_plugins) }
let(:local_installed_plugins) { {} }
before do
allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(plugin_manager)
allow(plugin_manager).to receive(:globalize!)
allow(plugin_manager).to receive(:localize!)
allow(plugin_manager).to receive(:load_plugins)
end
context "plugins are disabled" do
before{ allow(Vagrant).to receive(:plugins_enabled?).and_return(false) }
it "should return nil" do
expect(instance.send(:process_configured_plugins)).to be_nil
end
end
context "when vagrant is invalid" do
let(:vagrantfile) { 'Vagrant.configure("2"){ |config| config.vagrant.bad_key = true }' }
it "should raise a configuration error" do
expect { instance.send(:process_configured_plugins) }.to raise_error(Vagrant::Errors::ConfigInvalid)
end
end
context "with local plugins defined" do
let(:vagrantfile) { 'Vagrant.configure("2"){ |config| config.vagrant.plugins = "vagrant" }' }
let(:installed_plugins) { {"vagrant" => true} }
context "with plugin already installed" do
it "should not attempt to install a plugin" do
expect(plugin_manager).not_to receive(:install_plugin)
expect(instance.send(:process_configured_plugins)).to eq(local_installed_plugins)
end
end
context "without plugin installed" do
it "should prompt user before installation" do
expect(instance.ui).to receive(:ask).and_return("n")
expect(plugin_manager).to receive(:installed_plugins).and_return({})
expect { instance.send(:process_configured_plugins) }.to raise_error(Vagrant::Errors::PluginMissingLocalError)
end
it "should install plugin" do
expect(instance.ui).to receive(:ask).and_return("y")
expect(plugin_manager).to receive(:installed_plugins).and_return({})
expect(plugin_manager).to receive(:install_plugin).and_return(double("spec", "name" => "vagrant", "version" => "1"))
instance.send(:process_configured_plugins)
end
end
end
end
end end