Ensure internal trigger fire does not get called if plugin installed
This commit wraps up the internal machine action level trigger calls if the community vagrant-trigger plugin is installed.
This commit is contained in:
parent
83d102e708
commit
a177bcf4b7
|
@ -160,7 +160,11 @@ module Vagrant
|
||||||
# as extra data set on the environment hash for the middleware
|
# as extra data set on the environment hash for the middleware
|
||||||
# runner.
|
# runner.
|
||||||
def action(name, opts=nil)
|
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}")
|
@logger.info("Calling action: #{name} on provider #{@provider}")
|
||||||
|
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
|
@ -206,7 +210,9 @@ module Vagrant
|
||||||
action_result
|
action_result
|
||||||
end
|
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
|
# preserve returning environment after machine action runs
|
||||||
return return_env
|
return return_env
|
||||||
rescue Errors::EnvironmentLockedError
|
rescue Errors::EnvironmentLockedError
|
||||||
|
|
|
@ -265,6 +265,10 @@ describe Vagrant::Machine do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#action" do
|
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
|
it "should be able to run an action that exists" do
|
||||||
action_name = :up
|
action_name = :up
|
||||||
called = false
|
called = false
|
||||||
|
@ -387,6 +391,32 @@ describe Vagrant::Machine do
|
||||||
expect(subject.ui).to_not have_received(:warn)
|
expect(subject.ui).to_not have_received(:warn)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
describe "#action_raw" do
|
describe "#action_raw" do
|
||||||
|
|
Loading…
Reference in New Issue