summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-01-12 15:18:21 -0800
committerPaul Berry <paul@puppetlabs.com>2011-01-12 16:31:33 -0800
commit002f9f1905b089ebca628a6b743c0659e30ff9bc (patch)
tree2c9819169eeef9ee45f62df7793c391925d04ce6
parent94d71799f1ee196186bc3a8a5a1b06ef2ae0806e (diff)
downloadpuppet-002f9f1905b089ebca628a6b743c0659e30ff9bc.tar.gz
puppet-002f9f1905b089ebca628a6b743c0659e30ff9bc.tar.xz
puppet-002f9f1905b089ebca628a6b743c0659e30ff9bc.zip
(#5838) Improve the quality of file bucket specs.
Paired-with: Jesse Wolfe <jesse@puppetlabs.com>
-rwxr-xr-xspec/unit/file_bucket/dipper_spec.rb43
-rwxr-xr-xspec/unit/indirector/file_bucket_file/file_spec.rb59
2 files changed, 66 insertions, 36 deletions
diff --git a/spec/unit/file_bucket/dipper_spec.rb b/spec/unit/file_bucket/dipper_spec.rb
index 3e9e8b145..db40c6296 100755
--- a/spec/unit/file_bucket/dipper_spec.rb
+++ b/spec/unit/file_bucket/dipper_spec.rb
@@ -5,6 +5,8 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'pathname'
require 'puppet/file_bucket/dipper'
+require 'puppet/indirector/file_bucket_file/rest'
+
describe Puppet::FileBucket::Dipper do
include PuppetSpec::Files
@@ -34,14 +36,17 @@ describe Puppet::FileBucket::Dipper do
end
it "should backup files to a local bucket" do
- @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
+ Puppet[:bucketdir] = "/non/existent/directory"
+ file_bucket = tmpdir("bucket")
+
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => file_bucket)
file = make_tmp_file('my contents')
- checksum = Digest::MD5.hexdigest('my contents')
+ checksum = "2975f560750e71c478b8e3b39a956adb"
+ Digest::MD5.hexdigest('my contents').should == checksum
- Puppet::FileBucket::File.expects(:head).returns false
- Puppet::FileBucket::File.any_instance.expects(:save)
@dipper.backup(file).should == checksum
+ File.exists?("#{file_bucket}/2/9/7/5/f/5/6/0/2975f560750e71c478b8e3b39a956adb/contents").should == true
end
it "should not backup a file that is already in the bucket" do
@@ -60,11 +65,13 @@ describe Puppet::FileBucket::Dipper do
checksum = Digest::MD5.hexdigest('my contents')
- Puppet::FileBucket::File.expects(:find).with{|x,opts|
- x == "md5/#{checksum}"
- }.returns(Puppet::FileBucket::File.new('my contents'))
+ request = nil
+
+ Puppet::FileBucketFile::File.any_instance.expects(:find).with{ |r| request = r }.once.returns(Puppet::FileBucket::File.new('my contents'))
@dipper.getfile(checksum).should == 'my contents'
+
+ request.key.should == "md5/#{checksum}"
end
it "should backup files to a remote server" do
@@ -75,10 +82,18 @@ 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}")
+ request1 = nil
+ request2 = nil
+
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).with { |r| request1 = r }.once.returns(nil)
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).with { |r| request2 = r }.once
@dipper.backup(file).should == checksum
+ [request1, request2].each do |r|
+ r.server.should == 'puppetmaster'
+ r.port.should == 31337
+ r.key.should == "md5/#{checksum}"
+ end
end
it "should retrieve files from a remote server" do
@@ -86,10 +101,14 @@ describe Puppet::FileBucket::Dipper do
checksum = Digest::MD5.hexdigest('my contents')
- Puppet::FileBucket::File.expects(:find).with{|x,opts|
- x == "https://puppetmaster:31337/production/file_bucket_file/md5/#{checksum}"
- }.returns(Puppet::FileBucket::File.new('my contents'))
+ request = nil
+
+ Puppet::FileBucketFile::Rest.any_instance.expects(:find).with { |r| request = r }.returns(Puppet::FileBucket::File.new('my contents'))
@dipper.getfile(checksum).should == "my contents"
+
+ request.server.should == 'puppetmaster'
+ request.port.should == 31337
+ request.key.should == "md5/#{checksum}"
end
end
diff --git a/spec/unit/indirector/file_bucket_file/file_spec.rb b/spec/unit/indirector/file_bucket_file/file_spec.rb
index 6057fd2e6..cb614f36e 100755
--- a/spec/unit/indirector/file_bucket_file/file_spec.rb
+++ b/spec/unit/indirector/file_bucket_file/file_spec.rb
@@ -68,39 +68,50 @@ HERE
end
- describe "when retrieving files" do
- before :each do
- Puppet.settings.stubs(:use)
- @store = Puppet::FileBucketFile::File.new
+ [true, false].each do |override_bucket_path|
+ describe "when retrieving files and bucket path #{if override_bucket_path then 'is' else 'is not' end} overridden" do
+ before :each do
+ Puppet.settings.stubs(:use)
+ @store = Puppet::FileBucketFile::File.new
- @digest = "70924d6fa4b2d745185fa4660703a5c0"
+ @digest = "70924d6fa4b2d745185fa4660703a5c0"
- @bucket_dir = tmpdir("bucket")
+ @bucket_dir = tmpdir("bucket")
- Puppet.stubs(:[]).with(:bucketdir).returns(@bucket_dir)
+ if override_bucket_path
+ Puppet[:bucketdir] = "/bogus/path" # should not be used
+ else
+ Puppet[:bucketdir] = @bucket_dir
+ end
- @dir = "#{@bucket_dir}/7/0/9/2/4/d/6/f/70924d6fa4b2d745185fa4660703a5c0"
- @contents_path = "#{@dir}/contents"
+ @dir = "#{@bucket_dir}/7/0/9/2/4/d/6/f/70924d6fa4b2d745185fa4660703a5c0"
+ @contents_path = "#{@dir}/contents"
- @request = Puppet::Indirector::Request.new(:indirection_name, :find, "md5/#{@digest}")
- end
+ request_options = {}
+ if override_bucket_path
+ request_options[:bucket_path] = @bucket_dir
+ end
- def make_bucketed_file
- FileUtils.mkdir_p(@dir)
- File.open(@contents_path, 'w') { |f| f.write @contents }
- end
+ @request = Puppet::Indirector::Request.new(:indirection_name, :find, "md5/#{@digest}", request_options)
+ end
+
+ def make_bucketed_file
+ FileUtils.mkdir_p(@dir)
+ File.open(@contents_path, 'w') { |f| f.write @contents }
+ end
- it "should return an instance of Puppet::FileBucket::File created with the content if the file exists" do
- @contents = "my content"
- make_bucketed_file
+ it "should return an instance of Puppet::FileBucket::File created with the content if the file exists" do
+ @contents = "my content"
+ make_bucketed_file
- bucketfile = @store.find(@request)
- bucketfile.should be_a(Puppet::FileBucket::File)
- bucketfile.contents.should == @contents
- end
+ bucketfile = @store.find(@request)
+ bucketfile.should be_a(Puppet::FileBucket::File)
+ bucketfile.contents.should == @contents
+ end
- it "should return nil if no file is found" do
- @store.find(@request).should be_nil
+ it "should return nil if no file is found" do
+ @store.find(@request).should be_nil
+ end
end
end