summaryrefslogtreecommitdiffstats
path: root/spec/unit/resource
diff options
context:
space:
mode:
authorDan Bode <bodepd@gmail.com>2011-01-08 17:18:25 -0600
committerMatt Robinson <matt@puppetlabs.com>2011-01-24 16:44:41 -0800
commit18ca97b0d16fae149a1eab04c520421b5eb38969 (patch)
tree043de05a8f0b30838c7beafdaa9e5678c312c341 /spec/unit/resource
parent41090d3617d99f9eaa58df32be93f3d16467bc50 (diff)
downloadpuppet-18ca97b0d16fae149a1eab04c520421b5eb38969.tar.gz
puppet-18ca97b0d16fae149a1eab04c520421b5eb38969.tar.xz
puppet-18ca97b0d16fae149a1eab04c520421b5eb38969.zip
(#5045) Adds support to resource/type to also accept a param hash
The params are added as attributes when the resource is created. Also, even if the class already exists, if params are passed, we still try to create it. Reviewed-by: Matt Robinson
Diffstat (limited to 'spec/unit/resource')
-rwxr-xr-xspec/unit/resource/type_spec.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index 7b240bb82..11288f100 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -601,12 +601,37 @@ describe Puppet::Resource::Type do
@compiler.catalog.resource(:class, "top").should be_instance_of(Puppet::Parser::Resource)
end
+ it "should add specified attributes to the resource" do
+ @top.ensure_in_catalog(@scope, {'one'=>'1', 'two'=>'2'})
+ @compiler.catalog.resource(:class, "top")['one'].should == '1'
+ @compiler.catalog.resource(:class, "top")['two'].should == '2'
+ end
+
+ it "should not require params for a param class" do
+ @top.ensure_in_catalog(@scope, {})
+ @compiler.catalog.resource(:class, "top").should be_instance_of(Puppet::Parser::Resource)
+ end
+
it "should evaluate the parent class if one exists" do
@middle.ensure_in_catalog(@scope)
@compiler.catalog.resource(:class, "top").should be_instance_of(Puppet::Parser::Resource)
end
+ it "should evaluate the parent class if one exists" do
+ @middle.ensure_in_catalog(@scope, {})
+
+ @compiler.catalog.resource(:class, "top").should be_instance_of(Puppet::Parser::Resource)
+ end
+
+ it "should fail if you try to create duplicate class resources" do
+ othertop = Puppet::Parser::Resource.new(:class, 'top',:source => @source, :scope => @scope )
+ # add the same class resource to the catalog
+ @compiler.catalog.add_resource(othertop)
+ @compiler.catalog.expects(:resource).with(:class, 'top').returns true
+ lambda { @top.ensure_in_catalog(@scope, {}) }.should raise_error(Puppet::Resource::Catalog::DuplicateResourceError)
+ end
+
it "should fail to evaluate if a parent class is defined but cannot be found" do
othertop = Puppet::Resource::Type.new :hostclass, "something", :parent => "yay"
@code.add othertop