diff options
author | Luke Kanies <luke@puppetlabs.com> | 2010-05-17 12:22:31 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 89e8745e8c5c69775f8e1f680dceb39ba7a985ee (patch) | |
tree | f754cfb46dc8b4da9ec67c2369dd41f4135d9bc1 | |
parent | edcf4297628c704787ff2e7310271d9ccc019816 (diff) | |
download | puppet-89e8745e8c5c69775f8e1f680dceb39ba7a985ee.tar.gz puppet-89e8745e8c5c69775f8e1f680dceb39ba7a985ee.tar.xz puppet-89e8745e8c5c69775f8e1f680dceb39ba7a985ee.zip |
Fixing #2655 - Adding default parameter values to resources
We were previously just adding these values as variables in
the local scope, but we now add them to the resources so they
get passed to the client in the catalog and are thus inspectable.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
-rw-r--r-- | lib/puppet/resource/type.rb | 6 | ||||
-rwxr-xr-x | spec/unit/resource/type.rb | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 3657f89b5..627a1d5a2 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -204,7 +204,11 @@ class Puppet::Resource::Type # Even if 'default' is a false value, it's an AST value, so this works fine fail Puppet::ParseError, "Must pass #{param} to #{resource.ref}" unless default - scope.setvar(param.to_s, default.safeevaluate(scope)) + value = default.safeevaluate(scope) + scope.setvar(param.to_s, value) + + # Set it in the resource, too, so the value makes it to the client. + resource[param] = value end scope.setvar("title", resource.title) unless set.include? :title diff --git a/spec/unit/resource/type.rb b/spec/unit/resource/type.rb index 27c53936d..cd1881f8c 100755 --- a/spec/unit/resource/type.rb +++ b/spec/unit/resource/type.rb @@ -290,6 +290,14 @@ describe Puppet::Resource::Type do @scope.lookupvar("foo").should == "something" end + it "should set all default values as parameters in the resource" do + @type.set_arguments :foo => stub("value", :safeevaluate => "something") + + @type.set_resource_parameters(@resource, @scope) + + @resource[:foo].should == "something" + end + it "should fail if the resource does not provide a value for a required argument" do @type.set_arguments :foo => nil @resource.expects(:to_hash).returns({}) |