From 09b14120fe81a2955a1e4572ec0b8040ef540ade Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Wed, 17 Mar 2010 11:28:06 -0700 Subject: Fix tests on #3347 --- spec/unit/file_bucket/dipper.rb | 110 +++++++++++++++++++++++++++++++++++++ spec/unit/network/client/dipper.rb | 110 ------------------------------------- 2 files changed, 110 insertions(+), 110 deletions(-) create mode 100755 spec/unit/file_bucket/dipper.rb delete mode 100755 spec/unit/network/client/dipper.rb diff --git a/spec/unit/file_bucket/dipper.rb b/spec/unit/file_bucket/dipper.rb new file mode 100755 index 000000000..ffa2d4576 --- /dev/null +++ b/spec/unit/file_bucket/dipper.rb @@ -0,0 +1,110 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +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 + 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 + + 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(:exist?).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(:exist?).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(:exist?).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(:exist?).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 diff --git a/spec/unit/network/client/dipper.rb b/spec/unit/network/client/dipper.rb deleted file mode 100755 index 7d8b3da08..000000000 --- a/spec/unit/network/client/dipper.rb +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../../spec_helper' - -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 - File.stubs(:exists?).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 - - 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 -- cgit