summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-01-11 13:45:55 -0800
committerPaul Berry <paul@puppetlabs.com>2011-01-12 16:29:28 -0800
commit94d71799f1ee196186bc3a8a5a1b06ef2ae0806e (patch)
tree007f0c32a9c1380acdc90e57f7f29a5541d9d53d /spec/unit
parent89f56920f26544f7c5aa97785567b193034db151 (diff)
downloadpuppet-94d71799f1ee196186bc3a8a5a1b06ef2ae0806e.tar.gz
puppet-94d71799f1ee196186bc3a8a5a1b06ef2ae0806e.tar.xz
puppet-94d71799f1ee196186bc3a8a5a1b06ef2ae0806e.zip
(#5838) Make file bucket dipper efficient when saving a file that already exists
Before saving to the file bucket, the file bucket dipper now checks to make sure that no file with the given checksum is already present. Paired-with: Jesse Wolfe <jesse@puppetlabs.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/file_bucket/dipper_spec.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/unit/file_bucket/dipper_spec.rb b/spec/unit/file_bucket/dipper_spec.rb
index 730e10792..3e9e8b145 100755
--- a/spec/unit/file_bucket/dipper_spec.rb
+++ b/spec/unit/file_bucket/dipper_spec.rb
@@ -14,10 +14,20 @@ describe Puppet::FileBucket::Dipper do
file
end
+ it "should fail in an informative way when there are failures checking for the file on the server" do
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
+
+ file = make_tmp_file('contents')
+ Puppet::FileBucket::File.expects(:head).raises ArgumentError
+
+ lambda { @dipper.backup(file) }.should raise_error(Puppet::Error)
+ end
+
it "should fail in an informative way when there are failures backing up to the server" do
@dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
file = make_tmp_file('contents')
+ Puppet::FileBucket::File.expects(:head).returns false
Puppet::FileBucket::File.any_instance.expects(:save).raises ArgumentError
lambda { @dipper.backup(file) }.should raise_error(Puppet::Error)
@@ -29,10 +39,22 @@ describe Puppet::FileBucket::Dipper do
file = make_tmp_file('my contents')
checksum = Digest::MD5.hexdigest('my contents')
+ Puppet::FileBucket::File.expects(:head).returns false
Puppet::FileBucket::File.any_instance.expects(:save)
@dipper.backup(file).should == checksum
end
+ it "should not backup a file that is already in the bucket" do
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
+
+ file = make_tmp_file('my contents')
+ checksum = Digest::MD5.hexdigest('my contents')
+
+ Puppet::FileBucket::File.expects(:head).returns true
+ Puppet::FileBucket::File.any_instance.expects(:save).never
+ @dipper.backup(file).should == checksum
+ end
+
it "should retrieve files from a local bucket" do
@dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
@@ -53,6 +75,7 @@ describe Puppet::FileBucket::Dipper do
real_path = Pathname.new(file).realpath
+ Puppet::FileBucket::File.expects(:head).with("https://puppetmaster:31337/production/file_bucket_file/md5/#{checksum}").returns false
Puppet::FileBucket::File.any_instance.expects(:save).with("https://puppetmaster:31337/production/file_bucket_file/md5/#{checksum}")
@dipper.backup(file).should == checksum