summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-12-09 17:02:29 -0600
committerLuke Kanies <luke@madstop.com>2008-12-18 11:10:21 -0600
commite3b1590f57a18b89c5f97ca0aa8e8d2bd9187b58 (patch)
tree12a504efed000f16bbe1d45e9e6f71471714ae44 /spec/unit/parser
parentc306a1744793420337421f6fdf3630a9121861bd (diff)
Adding resource convertion to the parser resources
Also uses Puppet::Resource's method for creating transportable resources. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/resource.rb80
1 files changed, 80 insertions, 0 deletions
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 63cfbc2ed..37fd44387 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -333,4 +333,84 @@ describe Puppet::Parser::Resource do
end
+
+ it "should be able to be converted to a normal resource" do
+ @source = stub 'scope', :name => "myscope"
+ @resource = mkresource :source => @source
+ @resource.should respond_to(:to_resource)
+ end
+
+ it "should use its resource converter to convert to a transportable resource" do
+ @source = stub 'scope', :name => "myscope"
+ @resource = mkresource :source => @source
+
+ newresource = Puppet::Resource.new(:file, "/my")
+ Puppet::Resource.expects(:new).returns(newresource)
+
+ newresource.expects(:to_trans).returns "mytrans"
+
+ @resource.to_trans.should == "mytrans"
+ end
+
+ it "should return nil if converted to a transportable resource and it is virtual" do
+ @source = stub 'scope', :name => "myscope"
+ @resource = mkresource :source => @source
+
+ @resource.expects(:virtual?).returns true
+ @resource.to_trans.should be_nil
+ end
+
+ describe "when being converted to a resource" do
+ before do
+ @source = stub 'scope', :name => "myscope"
+ @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => "fum"}
+ end
+
+ it "should create an instance of Puppet::Resource" do
+ @parser_resource.to_resource.should be_instance_of(Puppet::Resource)
+ end
+
+ it "should set the type correctly on the Puppet::Resource" do
+ @parser_resource.to_resource.type.should == @parser_resource.type
+ end
+
+ it "should set the title correctly on the Puppet::Resource" do
+ @parser_resource.to_resource.title.should == @parser_resource.title
+ end
+
+ it "should copy over all of the parameters" do
+ @parser_resource.to_resource.to_hash.should == {:foo => "bar", :fee => "fum"}
+ end
+
+ it "should copy over the tags" do
+ @parser_resource.tag "foo"
+ @parser_resource.tag "bar"
+
+ @parser_resource.to_resource.tags.should == @parser_resource.tags
+ end
+
+ it "should copy over the line" do
+ @parser_resource.line = 40
+ @parser_resource.to_resource.line.should == 40
+ end
+
+ it "should copy over the file" do
+ @parser_resource.file = "/my/file"
+ @parser_resource.to_resource.file.should == "/my/file"
+ end
+
+ it "should convert any parser resource references to Puppet::Resource::Reference instances" do
+ ref = Puppet::Parser::Resource::Reference.new(:title => "/my/file", :type => "file")
+ @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ref}
+ result = @parser_resource.to_resource
+ result[:fee].should == Puppet::Resource::Reference.new(:file, "/my/file")
+ end
+
+ it "should convert any parser resource references to Puppet::Resource::Reference instances even if they are in an array" do
+ ref = Puppet::Parser::Resource::Reference.new(:title => "/my/file", :type => "file")
+ @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ["a", ref]}
+ result = @parser_resource.to_resource
+ result[:fee].should == ["a", Puppet::Resource::Reference.new(:file, "/my/file")]
+ end
+ end
end