summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-12-08 18:02:21 -0600
committerLuke Kanies <luke@madstop.com>2008-12-09 15:15:38 -0600
commite88746b48cfd4ce7cd9acd0baf61d9b660b460e9 (patch)
treee58bd5a140342ade2cfeae50412c533f36e82926 /spec
parent832198f56cfabc7a6ab1a97b99f61e278c16bc8b (diff)
Adding Trans{Object,Bucket} backward compatibility to Puppet::Resource
This is further progress toward #1808. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/resource.rb83
-rwxr-xr-xspec/unit/resource_reference.rb8
2 files changed, 91 insertions, 0 deletions
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index 9c936f0bb..b21a6fccb 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -193,4 +193,87 @@ describe Puppet::Resource do
@resource.to_manifest.should be_include(" foo => ['one','two']")
end
end
+
+ it "should be able to convert itself to a TransObject instance" do
+ Puppet::Resource.new("one::two", "/my/file").should respond_to(:to_trans)
+ end
+
+ describe "when converting to a TransObject" do
+ describe "and the resource is not an instance of a builtin type" do
+ before do
+ @resource = Puppet::Resource.new("foo", "bar")
+ end
+
+ it "should return a simple TransBucket if it is not an instance of a builtin type" do
+ bucket = @resource.to_trans
+ bucket.should be_instance_of(Puppet::TransBucket)
+ bucket.type.should == @resource.type
+ bucket.name.should == @resource.title
+ end
+
+ it "should copy over the resource's file" do
+ @resource.file = "/foo/bar"
+ @resource.to_trans.file.should == "/foo/bar"
+ end
+
+ it "should copy over the resource's line" do
+ @resource.line = 50
+ @resource.to_trans.line.should == 50
+ end
+ end
+
+ describe "and the resource is an instance of a builtin type" do
+ before do
+ @resource = Puppet::Resource.new("file", "bar")
+ end
+
+ it "should return a TransObject if it is an instance of a builtin resource type" do
+ trans = @resource.to_trans
+ trans.should be_instance_of(Puppet::TransObject)
+ trans.type.should == "file"
+ trans.name.should == @resource.title
+ end
+
+ it "should copy over the resource's file" do
+ @resource.file = "/foo/bar"
+ @resource.to_trans.file.should == "/foo/bar"
+ end
+
+ it "should copy over the resource's line" do
+ @resource.line = 50
+ @resource.to_trans.line.should == 50
+ end
+
+ # Only TransObjects support tags, annoyingly
+ it "should copy over the resource's tags" do
+ @resource.tag "foo"
+ @resource.to_trans.tags.should == @resource.tags
+ end
+
+ it "should copy the resource's parameters into the transobject and convert the parameter name to a string" do
+ @resource[:foo] = "bar"
+ @resource.to_trans["foo"].should == "bar"
+ end
+
+ it "should be able to copy arrays of values" do
+ @resource[:foo] = %w{yay fee}
+ @resource.to_trans["foo"].should == %w{yay fee}
+ end
+
+ it "should reduce single-value arrays to just a value" do
+ @resource[:foo] = %w{yay}
+ @resource.to_trans["foo"].should == "yay"
+ end
+
+ it "should convert resource references into the backward-compatible form" do
+ @resource[:foo] = Puppet::ResourceReference.new(:file, "/f")
+ @resource.to_trans["foo"].should == %w{file /f}
+ end
+
+ it "should convert resource references into the backward-compatible form even when within arrays" do
+ @resource[:foo] = ["a", Puppet::ResourceReference.new(:file, "/f")]
+ @resource.to_trans["foo"].should == ["a", %w{file /f}]
+ end
+ end
+ end
end
diff --git a/spec/unit/resource_reference.rb b/spec/unit/resource_reference.rb
index a81a8a0d1..baa3890cb 100755
--- a/spec/unit/resource_reference.rb
+++ b/spec/unit/resource_reference.rb
@@ -54,6 +54,14 @@ describe Puppet::ResourceReference do
it "should be not considered builtin if an existing resource type does not match the type" do
Puppet::ResourceReference.new("foobar", "/f").should_not be_builtin_type
end
+
+ it "should be able to produce a backward-compatible reference array" do
+ Puppet::ResourceReference.new("foobar", "/f").to_trans_ref.should == %w{Foobar /f}
+ end
+
+ it "should downcase resource types when producing a backward-compatible reference array for builtin resource types" do
+ Puppet::ResourceReference.new("file", "/f").to_trans_ref.should == %w{file /f}
+ end
end
describe Puppet::ResourceReference, "when resolving resources with a catalog" do