diff options
-rw-r--r-- | lib/puppet/parser/resource.rb | 6 | ||||
-rwxr-xr-x | spec/unit/parser/resource.rb | 15 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index b8aaf2715..651ed4224 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -139,6 +139,12 @@ class Puppet::Parser::Resource if params = options[:params] options.delete(:params) params.each do |param| + # Don't set the same parameter twice + if @params[param.name] + self.fail Puppet::ParseError, "Duplicate parameter '%s' for on %s" % + [param.name, self.to_s] + end + set_parameter(param) end end diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb index 0a67c4b54..3f08de958 100755 --- a/spec/unit/parser/resource.rb +++ b/spec/unit/parser/resource.rb @@ -25,7 +25,7 @@ describe Puppet::Parser::Resource do params = args[:params] || {:one => "yay", :three => "rah"} if args[:params] == :none args.delete(:params) - else + elsif not args[:params].is_a? Array args[:params] = paramify(args[:source], params) end @@ -483,5 +483,18 @@ describe Puppet::Parser::Resource do result = @parser_resource.to_resource result[:fee].should == ["a", Puppet::Resource::Reference.new(:file, "/my/file1"), Puppet::Resource::Reference.new(:file, "/my/file2")] end + + it "should fail if the same param is declared twice" do + lambda do + @parser_resource = mkresource :source => @source, :params => [ + Puppet::Parser::Resource::Param.new( + :name => :foo, :value => "bar", :source => @source + ), + Puppet::Parser::Resource::Param.new( + :name => :foo, :value => "baz", :source => @source + ) + ] + end.should raise_error(Puppet::ParseError) + end end end |