MultiStep does not allow composing steps that do not work together

This commit is contained in:
Mitchell Hashimoto 2011-12-06 18:31:07 -08:00
parent 73761dc92a
commit 822226cae4
2 changed files with 27 additions and 5 deletions

View File

@ -78,10 +78,22 @@ module Vagrant
maps[direct] = direct.variable maps[direct] = direct.variable
end end
# Take the missing inputs and map them together. For example
# the input of ':a' maps directly to the previous output of ':a'
(step_class.inputs - maps.values).each do |input|
maps[input] = input
end
# Turn the pure symbols into mapping from last steps # Turn the pure symbols into mapping from last steps
maps.keys.each do |from| maps.keys.each do |from|
if from.kind_of?(Symbol) if from.kind_of?(Symbol)
new_from = output(@step_names.last, from) new_from = nil
if @step_names.last.nil?
new_from = input(from)
else
new_from = output(@step_names.last, from)
end
maps[new_from] = maps.delete(from) maps[new_from] = maps.delete(from)
end end
end end
@ -122,10 +134,6 @@ module Vagrant
elsif from.kind_of?(StepOutput) elsif from.kind_of?(StepOutput)
# Step outputs get their data from a previous step's output. # Step outputs get their data from a previous step's output.
inputs[to] = step_outputs[from.name][from.variable] inputs[to] = step_outputs[from.name][from.variable]
else
# A basic remapping remaps the previous steps outputs to an
# input for this step.
inputs[to] = inputs.delete(from)
end end
end end

View File

@ -137,6 +137,20 @@ describe Vagrant::Action::MultiStep do
expect { g.step :foo }.to raise_error(ArgumentError) expect { g.step :foo }.to raise_error(ArgumentError)
end end
it "should not allow a step that doesn't have all inputs satisfied" do
step_A = Class.new(Vagrant::Action::Step) do
output :output_A
end
step_B = Class.new(Vagrant::Action::Step) do
input :input_B
end
g = described_class.new
g.step step_A
expect { g.step step_B }.to raise_error(ArgumentError)
end
it "should not allow remapping from outputs that don't exist" do it "should not allow remapping from outputs that don't exist" do
step_A = Class.new(Vagrant::Action::Step) do step_A = Class.new(Vagrant::Action::Step) do
output :output_A output :output_A