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
|
||||
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
|
||||
env = {
|
||||
:action_name => "machine_action_#{name}".to_sym,
|
||||
:machine => self,
|
||||
:machine_action => name,
|
||||
:ui => @ui
|
||||
action_name: "machine_action_#{name}".to_sym,
|
||||
machine: self,
|
||||
machine_action: name,
|
||||
ui: @ui,
|
||||
}.merge(extra_env || {})
|
||||
@env.action_runner.run(callable, env)
|
||||
end
|
||||
|
|
|
@ -261,6 +261,39 @@ describe Vagrant::Machine do
|
|||
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
|
||||
it "should return the SSH communicator by default" do
|
||||
expect(subject.communicate).
|
||||
|
|
Loading…
Reference in New Issue