[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5rc1-120-g2247c80
Paul Berry
paul at puppetlabs.com
Mon Feb 7 06:40:19 UTC 2011
The following commit has been merged in the upstream branch:
commit 9cfd3d58699b0d0c3ab53cb37226cade84d7ec64
Author: Paul Berry <paul at puppetlabs.com>
Date: Tue Jan 11 13:36:05 2011 -0800
(#5838) Reworked file dipper spec to perform less stubbing.
This is in preparation for adding more functionality to the file
dipper.
Paired-with: Jesse Wolfe <jesse at puppetlabs.com>
diff --git a/spec/unit/file_bucket/dipper_spec.rb b/spec/unit/file_bucket/dipper_spec.rb
index 799e899..86ad01f 100755
--- a/spec/unit/file_bucket/dipper_spec.rb
+++ b/spec/unit/file_bucket/dipper_spec.rb
@@ -2,121 +2,71 @@
require File.dirname(__FILE__) + '/../../spec_helper'
+require 'pathname'
+
require 'puppet/file_bucket/dipper'
describe Puppet::FileBucket::Dipper do
- before do
- ['/my/file'].each do |x|
- Puppet::FileBucket::Dipper.any_instance.stubs(:absolutize_path).with(x).returns(x)
- end
+ include PuppetSpec::Files
+
+ def make_tmp_file(contents)
+ file = tmpfile("file_bucket_file")
+ File.open(file, 'w') { |f| f.write(contents) }
+ file
end
it "should fail in an informative way when there are failures backing up to the server" do
- File.stubs(:exist?).returns true
- File.stubs(:read).returns "content"
-
@dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
- filemock = stub "bucketfile"
- Puppet::FileBucket::File.stubs(:new).returns(filemock)
- filemock.expects(:name).returns "name"
- filemock.expects(:save).raises ArgumentError
+ file = make_tmp_file('contents')
+ Puppet::FileBucket::File.any_instance.expects(:save).raises ArgumentError
- lambda { @dipper.backup("/my/file") }.should raise_error(Puppet::Error)
+ lambda { @dipper.backup(file) }.should raise_error(Puppet::Error)
end
it "should backup files to a local bucket" do
- @dipper = Puppet::FileBucket::Dipper.new(
- :Path => "/my/bucket"
- )
-
- File.stubs(:exist?).returns true
- File.stubs(:read).with("/my/file").returns "my contents"
-
- bucketfile = stub "bucketfile"
- bucketfile.stubs(:name).returns('md5/DIGEST123')
- bucketfile.stubs(:checksum_data).returns("DIGEST123")
- bucketfile.expects(:save).with('md5/DIGEST123')
-
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
- Puppet::FileBucket::File.stubs(:new).with(
-
- "my contents",
- :bucket_path => '/my/bucket',
-
- :path => '/my/file'
- ).returns(bucketfile)
+ file = make_tmp_file('my contents')
+ checksum = Digest::MD5.hexdigest('my contents')
- @dipper.backup("/my/file").should == "DIGEST123"
+ Puppet::FileBucket::File.any_instance.expects(:save)
+ @dipper.backup(file).should == checksum
end
it "should retrieve files from a local bucket" do
- @dipper = Puppet::FileBucket::Dipper.new(
- :Path => "/my/bucket"
- )
-
- File.stubs(:exist?).returns true
- File.stubs(:read).with("/my/file").returns "my contents"
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
- bucketfile = stub "bucketfile"
- bucketfile.stubs(:to_s).returns "Content"
+ checksum = Digest::MD5.hexdigest('my contents')
Puppet::FileBucket::File.expects(:find).with{|x,opts|
- x == 'md5/DIGEST123'
- }.returns(bucketfile)
+ x == "md5/#{checksum}"
+ }.returns(Puppet::FileBucket::File.new('my contents'))
- @dipper.getfile("DIGEST123").should == "Content"
+ @dipper.getfile(checksum).should == 'my contents'
end
it "should backup files to a remote server" do
+ @dipper = Puppet::FileBucket::Dipper.new(:Server => "puppetmaster", :Port => "31337")
- @dipper = Puppet::FileBucket::Dipper.new(
-
- :Server => "puppetmaster",
-
- :Port => "31337"
- )
-
- File.stubs(:exist?).returns true
- File.stubs(:read).with("/my/file").returns "my contents"
+ file = make_tmp_file('my contents')
+ checksum = Digest::MD5.hexdigest('my contents')
- bucketfile = stub "bucketfile"
- bucketfile.stubs(:name).returns('md5/DIGEST123')
- bucketfile.stubs(:checksum_data).returns("DIGEST123")
- bucketfile.expects(:save).with('https://puppetmaster:31337/production/file_bucket_file/md5/DIGEST123')
+ real_path = Pathname.new(file).realpath
+ Puppet::FileBucket::File.any_instance.expects(:save).with("https://puppetmaster:31337/production/file_bucket_file/md5/#{checksum}/#{real_path}")
- Puppet::FileBucket::File.stubs(:new).with(
-
- "my contents",
- :bucket_path => nil,
-
- :path => '/my/file'
- ).returns(bucketfile)
-
- @dipper.backup("/my/file").should == "DIGEST123"
+ @dipper.backup(file).should == checksum
end
it "should retrieve files from a remote server" do
+ @dipper = Puppet::FileBucket::Dipper.new(:Server => "puppetmaster", :Port => "31337")
- @dipper = Puppet::FileBucket::Dipper.new(
-
- :Server => "puppetmaster",
-
- :Port => "31337"
- )
-
- File.stubs(:exist?).returns true
- File.stubs(:read).with("/my/file").returns "my contents"
-
- bucketfile = stub "bucketfile"
- bucketfile.stubs(:to_s).returns "Content"
+ checksum = Digest::MD5.hexdigest('my contents')
Puppet::FileBucket::File.expects(:find).with{|x,opts|
- x == 'https://puppetmaster:31337/production/file_bucket_file/md5/DIGEST123'
- }.returns(bucketfile)
+ x == "https://puppetmaster:31337/production/file_bucket_file/md5/#{checksum}"
+ }.returns(Puppet::FileBucket::File.new('my contents'))
- @dipper.getfile("DIGEST123").should == "Content"
+ @dipper.getfile(checksum).should == "my contents"
end
-
-
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list