summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorSteven Jenkins <steven@endpoint.com>2009-07-24 12:31:36 -0400
committerLuke Kanies <luke@madstop.com>2009-08-03 15:02:56 -0700
commit8f60f0c50ee3dfb6453644f5dcded58e6e80e8bb (patch)
tree3085661bf0c71dea350adf8a666784b350c2ad66 /spec/unit
parentcd224c6c9f5dedd27bb59822e240b5bae6202ab0 (diff)
downloadpuppet-8f60f0c50ee3dfb6453644f5dcded58e6e80e8bb.tar.gz
puppet-8f60f0c50ee3dfb6453644f5dcded58e6e80e8bb.tar.xz
puppet-8f60f0c50ee3dfb6453644f5dcded58e6e80e8bb.zip
Fixes for Redmine 2371.
This changes the condition checking of handlebucket, as well as moves it (and remove_backup) into a separate module. It additionally refactors common code out of handlebucket into separate private methods. Some new RSpec tests which use mock and stubs are added as well, including removing the old test/ral/type/filebucket.rb tests since they are already covered by RSpec tests.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/util/backups.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/unit/util/backups.rb b/spec/unit/util/backups.rb
new file mode 100755
index 000000000..2ddab5e85
--- /dev/null
+++ b/spec/unit/util/backups.rb
@@ -0,0 +1,68 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/type/file'
+require 'puppet/util/backups'
+include PuppetTest
+
+describe Puppet::Util::Backups do
+ describe "when backing up a file" do
+ it "should succeed silently if the file does not exist" do
+ Puppet::Type::File.new(:name => '/no/such/file').perform_backup.should be_true
+ end
+ it "should succeed silently if self[:backup] is false" do
+ FileTest.stubs(:exists?).returns true
+ Puppet::Type::File.new(:name => '/some/file', :backup => false).perform_backup.should be_true
+ end
+ it "a bucket should work when provided" do
+ path = '/my/file'
+
+ FileTest.stubs(:exists?).with(path).returns true
+ File.stubs(:stat).with(path).returns(mock('stat', :ftype => 'file'))
+
+ bucket = mock('bucket', 'name' => 'foo')
+ bucket.expects(:backup).with(path)
+
+ file = Puppet::Type::File.new(:name => path, :backup => 'foo')
+ file.stubs(:bucket).returns bucket
+
+ file.perform_backup.should be_nil
+ end
+ it "a local backup should work" do
+ path = '/my/file'
+ FileTest.stubs(:exists?).with(path).returns true
+
+ file = Puppet::Type::File.new(:name => path, :backup => '.foo')
+ file.stubs(:perform_backup_with_backuplocal).returns true
+ file.perform_backup.should be_true
+ end
+ end
+ describe "when backing up a directory" do
+ it "a bucket should work when provided" do
+ path = '/my/dir'
+
+ FileTest.stubs(:exists?).with(path).returns true
+ File.stubs(:stat).with(path).returns(mock('stat', :ftype => 'directory'))
+ Find.stubs(:find).returns('')
+
+ #bucket = mock('bucket', 'name' => 'foo')
+ bucket = mock('bucket')
+ bucket.stubs(:backup).with(path).returns true
+
+ file = Puppet::Type::File.new(:name => path, :backup => 'foo')
+ file.stubs(:bucket).returns bucket
+
+ file.perform_backup.should be_true
+ end
+ it "a local backup should work" do
+ path = '/my/dir'
+ FileTest.stubs(:exists?).with(path).returns true
+
+ file = Puppet::Type::File.new(:name => path, :backup => '.foo')
+ file.stubs(:perform_backup_with_backuplocal).returns true
+ file.perform_backup.should be_true
+ end
+ end
+end
+