diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-03-15 14:16:09 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | e5a78009f6bd593e7e3957f0dadb470e623396dd (patch) | |
| tree | f1d386962e4a7ef5b4e20347653e570dccd141bf /spec/unit/network/client | |
| parent | f838389da0530201849958444dbbe60977935ad0 (diff) | |
| download | puppet-e5a78009f6bd593e7e3957f0dadb470e623396dd.tar.gz puppet-e5a78009f6bd593e7e3957f0dadb470e623396dd.tar.xz puppet-e5a78009f6bd593e7e3957f0dadb470e623396dd.zip | |
Feature #3347 REST-ified FileBucket
FileBucket Files have been reimplemented as an indirector terminus so that
they can be transmitted over REST.
The old Network::Client.dipper has been replaced with a compatibility later
in FileBucket::Dipper that uses the indirector to access filebucket termini.
Slightly revised patch:
* No longer allows nil contents in FileBucket outside of initialization
* Uses File.exist? instead of the deprecated File.exists?
* Tweaks JSON serialization and de-serialization to include "path"
Deferred issues:
* Feature #3371 "FileBucket should not keep files in memory".
* Feature #3372 "Replace FileBucket Dipper with more idiomatic calls"
Diffstat (limited to 'spec/unit/network/client')
| -rwxr-xr-x | spec/unit/network/client/dipper.rb | 102 |
1 files changed, 98 insertions, 4 deletions
diff --git a/spec/unit/network/client/dipper.rb b/spec/unit/network/client/dipper.rb index d1631fbb5..7d8b3da08 100755 --- a/spec/unit/network/client/dipper.rb +++ b/spec/unit/network/client/dipper.rb @@ -2,15 +2,109 @@ require File.dirname(__FILE__) + '/../../../spec_helper' -describe Puppet::Network::Client.dipper do +require 'puppet/file_bucket/dipper' +describe Puppet::FileBucket::Dipper do it "should fail in an informative way when there are failures backing up to the server" do - FileTest.stubs(:exists?).returns true + File.stubs(:exists?).returns true File.stubs(:read).returns "content" - @dipper = Puppet::Network::Client::Dipper.new(:Path => "/my/bucket") + @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket") - @dipper.driver.expects(:addfile).raises ArgumentError + filemock = stub "bucketfile" + Puppet::FileBucket::File.stubs(:new).returns(filemock) + filemock.expects(:name).returns "name" + filemock.expects(:save).raises ArgumentError lambda { @dipper.backup("/my/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(:exists?).returns true + File.stubs(:read).with("/my/file").returns "my contents" + + req = stub "req" + bucketfile = stub "bucketfile" + bucketfile.stubs(:name).returns('md5/DIGEST123') + bucketfile.stubs(:checksum_data).returns("DIGEST123") + bucketfile.expects(:save).with(req) + + Puppet::FileBucket::File.stubs(:new).with( + "my contents", + :bucket_path => '/my/bucket', + :path => '/my/file' + ).returns(bucketfile) + + Puppet::Indirector::Request.stubs(:new).with(:file_bucket_file, :save, 'md5/DIGEST123').returns(req) + + @dipper.backup("/my/file").should == "DIGEST123" + end + + it "should retrieve files from a local bucket" do + @dipper = Puppet::FileBucket::Dipper.new( + :Path => "/my/bucket" + ) + + File.stubs(:exists?).returns true + File.stubs(:read).with("/my/file").returns "my contents" + + bucketfile = stub "bucketfile" + bucketfile.stubs(:to_s).returns "Content" + + Puppet::FileBucket::File.expects(:find).with( + 'md5/DIGEST123' + ).returns(bucketfile) + + @dipper.getfile("DIGEST123").should == "Content" + end + + it "should backup files to a remote server" do + @dipper = Puppet::FileBucket::Dipper.new( + :Server => "puppetmaster", + :Port => "31337" + ) + + File.stubs(:exists?).returns true + File.stubs(:read).with("/my/file").returns "my contents" + + req = stub "req" + bucketfile = stub "bucketfile" + bucketfile.stubs(:name).returns('md5/DIGEST123') + bucketfile.stubs(:checksum_data).returns("DIGEST123") + bucketfile.expects(:save).with(req) + + Puppet::FileBucket::File.stubs(:new).with( + "my contents", + :bucket_path => nil, + :path => '/my/file' + ).returns(bucketfile) + + Puppet::Indirector::Request.stubs(:new).with(:file_bucket_file, :save, 'https://puppetmaster:31337/production/file_bucket_file/md5/DIGEST123').returns(req) + + @dipper.backup("/my/file").should == "DIGEST123" + end + + it "should retrieve files from a remote server" do + @dipper = Puppet::FileBucket::Dipper.new( + :Server => "puppetmaster", + :Port => "31337" + ) + + File.stubs(:exists?).returns true + File.stubs(:read).with("/my/file").returns "my contents" + + bucketfile = stub "bucketfile" + bucketfile.stubs(:to_s).returns "Content" + + Puppet::FileBucket::File.expects(:find).with( + 'https://puppetmaster:31337/production/file_bucket_file/md5/DIGEST123' + ).returns(bucketfile) + + @dipper.getfile("DIGEST123").should == "Content" + end + + end |
