summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorDan Bode <bodepd@gmail.com>2010-10-24 00:49:03 -0500
committerPaul Berry <paul@puppetlabs.com>2011-02-01 15:49:52 -0800
commitce5a2bf3ba66d5ce723a6887580b008e8ba4104b (patch)
tree7845397d260a57391a8c1adbfe8bbf746d248e7d /spec/unit
parent1ab9bd833237c7cf2036989a58a1b22d3cc49a5b (diff)
(#5061) - allow special hostclass/define variables to be evaluated as defaults.
I have always been annoyed that special variables for defines and hostclasses can not be evaluated as param defaults. Special variables are: $name, $title, $module_name. Code example: class x ( foo = $name ) { notice($foo)} should print x, and with my patch, it does. Reviewed-by: Paul Berry <paul@puppetlabs.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/resource/type_spec.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index 7b240bb82..dc4d03259 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -261,6 +261,28 @@ describe Puppet::Resource::Type do
@type = Puppet::Resource::Type.new(:hostclass, "foo")
end
+ ['module_name', 'name', 'title'].each do |variable|
+ it "should allow #{variable} to be evaluated as param default" do
+ @type.module_name = "bar"
+ var = Puppet::Parser::AST::Variable.new({'value' => variable})
+ @type.set_arguments :foo => var
+ @type.set_resource_parameters(@resource, @scope)
+ @scope.lookupvar('foo').should == 'bar'
+ end
+ end
+
+ # this test is to clarify a crazy edge case
+ # if you specify these special names as params, the resource
+ # will override the special variables
+ it "resource should override defaults" do
+ @type.set_arguments :name => nil
+ @resource[:name] = 'foobar'
+ var = Puppet::Parser::AST::Variable.new({'value' => 'name'})
+ @type.set_arguments :foo => var
+ @type.set_resource_parameters(@resource, @scope)
+ @scope.lookupvar('foo').should == 'foobar'
+ end
+
it "should set each of the resource's parameters as variables in the scope" do
@type.set_arguments :foo => nil, :boo => nil
@resource[:foo] = "bar"