core: Machine#action_raw for calling raw callables
This commit is contained in:
parent
d8bdb62ed4
commit
0153e0ccbb
|
@ -158,12 +158,23 @@ module Vagrant
|
||||||
:provider => @provider.to_s
|
:provider => @provider.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
action_raw(name, callable, extra_env)
|
||||||
|
end
|
||||||
|
|
||||||
|
# This calls a raw callable in the proper context of the machine using
|
||||||
|
# the middleware stack.
|
||||||
|
#
|
||||||
|
# @param [Symbol] name Name of the action
|
||||||
|
# @param [Proc] callable
|
||||||
|
# @param [Hash] extra_env Extra env for the action env.
|
||||||
|
# @return [Hash] The resulting env
|
||||||
|
def action_raw(name, callable, extra_env=nil)
|
||||||
# Run the action with the action runner on the environment
|
# Run the action with the action runner on the environment
|
||||||
env = {
|
env = {
|
||||||
:action_name => "machine_action_#{name}".to_sym,
|
action_name: "machine_action_#{name}".to_sym,
|
||||||
:machine => self,
|
machine: self,
|
||||||
:machine_action => name,
|
machine_action: name,
|
||||||
:ui => @ui
|
ui: @ui,
|
||||||
}.merge(extra_env || {})
|
}.merge(extra_env || {})
|
||||||
@env.action_runner.run(callable, env)
|
@env.action_runner.run(callable, env)
|
||||||
end
|
end
|
||||||
|
|
|
@ -261,6 +261,39 @@ describe Vagrant::Machine do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#action_raw" do
|
||||||
|
let(:callable) {lambda { |e|
|
||||||
|
e[:called] = true
|
||||||
|
@env = e
|
||||||
|
}}
|
||||||
|
|
||||||
|
before do
|
||||||
|
@env = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should run the callable with the proper env" do
|
||||||
|
subject.action_raw(:foo, callable)
|
||||||
|
|
||||||
|
expect(@env[:called]).to be_true
|
||||||
|
expect(@env[:action_name]).to eq(:machine_action_foo)
|
||||||
|
expect(@env[:machine]).to equal(subject)
|
||||||
|
expect(@env[:machine_action]).to eq(:foo)
|
||||||
|
expect(@env[:ui]).to equal(subject.ui)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return the environment as a result" do
|
||||||
|
result = subject.action_raw(:foo, callable)
|
||||||
|
expect(result).to equal(@env)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should merge in any extra env" do
|
||||||
|
subject.action_raw(:bar, callable, foo: :bar)
|
||||||
|
|
||||||
|
expect(@env[:called]).to be_true
|
||||||
|
expect(@env[:foo]).to eq(:bar)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#communicate" do
|
describe "#communicate" do
|
||||||
it "should return the SSH communicator by default" do
|
it "should return the SSH communicator by default" do
|
||||||
expect(subject.communicate).
|
expect(subject.communicate).
|
||||||
|
|
Loading…
Reference in New Issue