summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-26 23:12:03 -0700
committerLuke Kanies <luke@madstop.com>2008-08-26 23:12:03 -0700
commitbe4c0e7fbe5e652ec1d49eab2fdc7a5fbbc486f3 (patch)
tree395386c1549d19263f2baa5be8c4bebcce7a04f8 /spec
parent44c6a529d0a84d844b21f96d64de674487238f53 (diff)
downloadpuppet-be4c0e7fbe5e652ec1d49eab2fdc7a5fbbc486f3.tar.gz
puppet-be4c0e7fbe5e652ec1d49eab2fdc7a5fbbc486f3.tar.xz
puppet-be4c0e7fbe5e652ec1d49eab2fdc7a5fbbc486f3.zip
The file source is now refactored and uses REST.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/type/file.rb48
-rwxr-xr-xspec/unit/type/file/source.rb81
2 files changed, 89 insertions, 40 deletions
diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb
index 7f9688f0b..8b7bedee6 100755
--- a/spec/unit/type/file.rb
+++ b/spec/unit/type/file.rb
@@ -31,46 +31,6 @@ describe Puppet::Type.type(:file) do
end
end
- describe "when specifying a source" do
- before do
- @file[:source] = "/bar"
- end
-
- it "should raise if source doesn't exist" do
- @file.property(:source).expects(:found?).returns(false)
- lambda { @file.retrieve }.should raise_error(Puppet::Error)
- end
-
- end
-
- describe "when retrieving remote files" do
- before do
- @filesource = Puppet::Type::File::FileSource.new
- @filesource.server = mock 'fileserver'
-
- @file.stubs(:uri2obj).returns(@filesource)
-
- @file[:source] = "puppet:///test"
- end
-
- it "should fail without writing if it cannot retrieve remote contents" do
- # create the file, because we only get the problem when it starts
- # out absent.
- File.open(@file[:path], "w") { |f| f.puts "a" }
- @file.expects(:write).never
-
- @filesource.server.stubs(:describe).returns("493\tfile\t100\t0\t{md5}3f5fef3bddbc4398c46a7bd7ba7b3af7")
- @filesource.server.stubs(:retrieve).raises(RuntimeError)
- @file.property(:source).retrieve
- lambda { @file.property(:source).sync }.should raise_error(Puppet::Error)
- end
-
- it "should fail if it cannot describe remote contents" do
- @filesource.server.stubs(:describe).raises(Puppet::Network::XMLRPCClientError.new("Testing"))
- lambda { @file.retrieve }.should raise_error(Puppet::Error)
- end
- end
-
describe "when managing links" do
require 'puppettest/support/assertions'
include PuppetTest
@@ -110,4 +70,12 @@ describe Puppet::Type.type(:file) do
("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0755
end
end
+
+ describe "when flushing" do
+ it "should flush all properties that respond to :flush" do
+ @resource = Puppet.type(:file).create(:path => "/foo/bar", :source => "/bar/foo")
+ @resource.property(:source).expects(:flush)
+ @resource.flush
+ end
+ end
end
diff --git a/spec/unit/type/file/source.rb b/spec/unit/type/file/source.rb
index bb689ce76..d6aa25fe7 100755
--- a/spec/unit/type/file/source.rb
+++ b/spec/unit/type/file/source.rb
@@ -173,4 +173,85 @@ describe Puppet::Type.type(:file).attrclass(:source) do
@source.retrieve
end
end
+
+ describe "when flushing" do
+ it "should set its metadata to nil" do
+ @source = source.new(:resource => @resource)
+ @source.metadata = "foo"
+ @source.flush
+ @source.instance_variable_get("@metadata").should be_nil
+ end
+
+ it "should reset its content" do
+ @source = source.new(:resource => @resource)
+ @source.instance_variable_set("@content", "foo")
+ @source.flush
+ @source.instance_variable_get("@content").should be_nil
+ end
+ end
+
+ it "should have a method for returning the content" do
+ source.new(:resource => @resource).must respond_to(:content)
+ end
+
+ describe "when looking up the content" do
+ before do
+ @source = source.new(:resource => @resource)
+ @metadata = stub 'metadata', :source => "/my/source"
+ @source.metadata = @metadata
+
+ @content = stub 'content', :content => "foobar"
+ end
+
+ it "should fail if the metadata does not have a source set" do
+ @metadata.stubs(:source).returns nil
+ lambda { @source.content }.should raise_error(Puppet::DevError)
+ end
+
+ it "should look the content up from the Content class using the metadata source if no content is set" do
+ Puppet::FileServing::Content.expects(:find).with("/my/source").returns @content
+ @source.content.should == "foobar"
+ end
+
+ it "should return previously found content" do
+ Puppet::FileServing::Content.expects(:find).with("/my/source").returns @content
+ @source.content.should == "foobar"
+ @source.content.should == "foobar"
+ end
+
+ it "should fail if no content can be retrieved" do
+ Puppet::FileServing::Content.expects(:find).with("/my/source").returns nil
+ @source.expects(:fail).raises RuntimeError
+ lambda { @source.content }.should raise_error(RuntimeError)
+ end
+ end
+
+ describe "when changing the content" do
+ before do
+ @source = source.new(:resource => @resource)
+ @source.stubs(:content).returns "foobar"
+
+ @metadata = stub 'metadata', :checksum => 123
+ @source.metadata = @metadata
+ @resource.stubs(:[]).with(:path).returns "/boo"
+ end
+
+ it "should use the file's :write method to write the content" do
+ @resource.expects(:write).with("foobar", :source, 123)
+
+ @source.sync
+ end
+
+ it "should return :file_changed if the file already existed" do
+ @resource.stubs(:write)
+ FileTest.expects(:exist?).with("/boo").returns true
+ @source.sync.should == :file_changed
+ end
+
+ it "should return :file_created if the file already existed" do
+ @resource.stubs(:write)
+ FileTest.expects(:exist?).with("/boo").returns false
+ @source.sync.should == :file_created
+ end
+ end
end