Merge pull request #9799 from briancain/guard-trigger-calls

Ensure internal trigger fire does not get called if plugin installed
This commit is contained in:
Brian Cain 2018-05-07 12:24:34 -07:00 committed by GitHub
commit e75260d471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View File

@ -160,7 +160,11 @@ module Vagrant
# as extra data set on the environment hash for the middleware
# runner.
def action(name, opts=nil)
@triggers.fire_triggers(name, :before, @name.to_s)
plugins = Vagrant::Plugin::Manager.instance.installed_plugins
if !plugins.keys.include?("vagrant-triggers")
@triggers.fire_triggers(name, :before, @name.to_s)
end
@logger.info("Calling action: #{name} on provider #{@provider}")
opts ||= {}
@ -206,7 +210,9 @@ module Vagrant
action_result
end
@triggers.fire_triggers(name, :after, @name.to_s)
if !plugins.keys.include?("vagrant-triggers")
@triggers.fire_triggers(name, :after, @name.to_s)
end
# preserve returning environment after machine action runs
return return_env
rescue Errors::EnvironmentLockedError

View File

@ -265,6 +265,10 @@ describe Vagrant::Machine do
end
describe "#action" do
before do
allow(Vagrant::Plugin::Manager.instance).to receive(:installed_plugins).and_return({})
end
it "should be able to run an action that exists" do
action_name = :up
called = false
@ -387,6 +391,32 @@ describe Vagrant::Machine do
expect(subject.ui).to_not have_received(:warn)
end
end
context "with the vagrant-triggers community plugin" do
it "should not call the internal trigger functions if installed" do
action_name = :up
callable = lambda { |_env| }
allow(provider).to receive(:action).with(action_name).and_return(callable)
allow(Vagrant::Plugin::Manager.instance).to receive(:installed_plugins)
.and_return({"vagrant-triggers"=>"stuff"})
expect(instance.instance_variable_get(:@triggers)).not_to receive(:fire_triggers)
instance.action(action_name)
end
it "should call the internal trigger functions if not installed" do
action_name = :up
callable = lambda { |_env| }
allow(provider).to receive(:action).with(action_name).and_return(callable)
allow(Vagrant::Plugin::Manager.instance).to receive(:installed_plugins)
.and_return({})
expect(instance.instance_variable_get(:@triggers)).to receive(:fire_triggers).twice
instance.action(action_name)
end
end
end
describe "#action_raw" do