diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2010-03-21 12:07:37 +0100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2010-03-24 08:15:07 +1100 |
commit | 751df45547162632c41cf98a1b1daabbadb1b901 (patch) | |
tree | 6bef1b3ef4daa80cf0073f639f1c376f8fd6a744 | |
parent | a1d216c74ee7245e0edaaba7d9384b59d442bcf2 (diff) | |
download | puppet-751df45547162632c41cf98a1b1daabbadb1b901.tar.gz puppet-751df45547162632c41cf98a1b1daabbadb1b901.tar.xz puppet-751df45547162632c41cf98a1b1daabbadb1b901.zip |
Fix #3186 - require function set relationship only on the last class
Due to the fact that resource.set_parameter is overwriting the previous
set_parameters, we were losing the previous relationships we set there,
either in a previous call of require or in the same call.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
-rw-r--r-- | lib/puppet/parser/functions/require.rb | 2 | ||||
-rwxr-xr-x | spec/integration/parser/functions/require.rb | 19 | ||||
-rwxr-xr-x | spec/unit/parser/functions/require.rb | 14 |
3 files changed, 31 insertions, 4 deletions
diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb index 3e7961933..f634f9fbd 100644 --- a/lib/puppet/parser/functions/require.rb +++ b/lib/puppet/parser/functions/require.rb @@ -50,7 +50,7 @@ fail if used with earlier clients. # but that is considered a containment edge, not a dependency # edge, so it usually gets lost on the client. ref = Puppet::Parser::Resource::Reference.new(:type => :class, :title => klass) - resource.set_parameter(:require, ref) + resource.set_parameter(:require, [resource[:require]].flatten.compact << ref) end end end diff --git a/spec/integration/parser/functions/require.rb b/spec/integration/parser/functions/require.rb index 960594b21..6f169ade1 100755 --- a/spec/integration/parser/functions/require.rb +++ b/spec/integration/parser/functions/require.rb @@ -22,10 +22,27 @@ describe "the require function" do @scope.function_require("requiredclass") @scope.resource["require"].should_not be_nil - ref = @scope.resource["require"] + ref = @scope.resource["require"].shift ref.type.should == "Class" ref.title.should == "requiredclass" end + + it "should queue relationships between the 'required' class and our classes" do + @parser.newclass("requiredclass1") + @parser.newclass("requiredclass2") + + @scope.function_require("requiredclass1") + @scope.function_require("requiredclass2") + + @scope.resource["require"].should_not be_nil + + (ref1,ref2) = @scope.resource["require"] + ref1.type.should == "Class" + ref1.title.should == "requiredclass1" + ref2.type.should == "Class" + ref2.title.should == "requiredclass2" + end + end describe "the include function" do diff --git a/spec/unit/parser/functions/require.rb b/spec/unit/parser/functions/require.rb index 532c06900..4e05069df 100755 --- a/spec/unit/parser/functions/require.rb +++ b/spec/unit/parser/functions/require.rb @@ -8,7 +8,7 @@ describe "the require function" do @catalog = stub 'catalog' @compiler = stub 'compiler', :catalog => @catalog - @resource = stub 'resource', :set_parameter => nil, :metaparam_compatibility_mode? => false + @resource = stub 'resource', :set_parameter => nil, :metaparam_compatibility_mode? => false, :[] => nil @scope = Puppet::Parser::Scope.new() @scope.stubs(:resource).returns @resource @scope.stubs(:findresource) @@ -28,7 +28,7 @@ describe "the require function" do end it "should set the 'require' prarameter on the resource to a resource reference" do - @resource.expects(:set_parameter).with { |name, value| name == :require and value.is_a?(Puppet::Parser::Resource::Reference) } + @resource.expects(:set_parameter).with { |name, value| name == :require and value[0].is_a?(Puppet::Parser::Resource::Reference) } @scope.stubs(:function_include) @scope.function_require("myclass") end @@ -56,4 +56,14 @@ describe "the require function" do @scope.function_require("myclass") end + + it "should append the required class to the require parameter" do + @scope.stubs(:function_include) + Puppet::Parser::Resource::Reference.stubs(:new).returns(:require2) + + @resource.expects(:[]).with(:require).returns(:require1) + @resource.expects(:set_parameter).with(:require, [:require1, :require2]) + + @scope.function_require("myclass") + end end |