backup_checksum 3.0.23
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup_checksum might be problematic. Click here for more details.
- data/.gitignore +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Gemfile.lock +130 -0
- data/Guardfile +21 -0
- data/LICENSE.md +24 -0
- data/README.md +476 -0
- data/backup_checksum.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +217 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/checksum/base.rb +44 -0
- data/lib/backup/checksum/shasum.rb +16 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +88 -0
- data/lib/backup/cli/utility.rb +247 -0
- data/lib/backup/compressor/base.rb +29 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/gzip.rb +47 -0
- data/lib/backup/compressor/lzma.rb +50 -0
- data/lib/backup/compressor/pbzip2.rb +56 -0
- data/lib/backup/config.rb +173 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/checksum/base.rb +9 -0
- data/lib/backup/configuration/checksum/shasum.rb +9 -0
- data/lib/backup/configuration/compressor/base.rb +9 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/compressor/lzma.rb +23 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/base.rb +19 -0
- data/lib/backup/configuration/database/mongodb.rb +49 -0
- data/lib/backup/configuration/database/mysql.rb +42 -0
- data/lib/backup/configuration/database/postgresql.rb +41 -0
- data/lib/backup/configuration/database/redis.rb +39 -0
- data/lib/backup/configuration/database/riak.rb +29 -0
- data/lib/backup/configuration/encryptor/base.rb +9 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +32 -0
- data/lib/backup/configuration/helpers.rb +52 -0
- data/lib/backup/configuration/notifier/base.rb +28 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +112 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +25 -0
- data/lib/backup/configuration/storage/dropbox.rb +58 -0
- data/lib/backup/configuration/storage/ftp.rb +29 -0
- data/lib/backup/configuration/storage/local.rb +17 -0
- data/lib/backup/configuration/storage/ninefold.rb +20 -0
- data/lib/backup/configuration/storage/rsync.rb +29 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/cloud.rb +23 -0
- data/lib/backup/configuration/syncer/cloud_files.rb +30 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +23 -0
- data/lib/backup/database/base.rb +59 -0
- data/lib/backup/database/mongodb.rb +232 -0
- data/lib/backup/database/mysql.rb +163 -0
- data/lib/backup/database/postgresql.rb +146 -0
- data/lib/backup/database/redis.rb +139 -0
- data/lib/backup/database/riak.rb +69 -0
- data/lib/backup/dependency.rb +114 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +80 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +386 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +168 -0
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/presently.rb +88 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +51 -0
- data/lib/backup/packager.rb +108 -0
- data/lib/backup/pipeline.rb +107 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +119 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +181 -0
- data/lib/backup/storage/ftp.rb +119 -0
- data/lib/backup/storage/local.rb +82 -0
- data/lib/backup/storage/ninefold.rb +116 -0
- data/lib/backup/storage/rsync.rb +149 -0
- data/lib/backup/storage/s3.rb +94 -0
- data/lib/backup/storage/scp.rb +99 -0
- data/lib/backup/storage/sftp.rb +108 -0
- data/lib/backup/syncer/base.rb +42 -0
- data/lib/backup/syncer/cloud.rb +190 -0
- data/lib/backup/syncer/cloud_files.rb +56 -0
- data/lib/backup/syncer/rsync/base.rb +52 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +47 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +176 -0
- data/spec/cli/utility_spec.rb +363 -0
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +83 -0
- data/spec/compressor/gzip_spec.rb +83 -0
- data/spec/compressor/lzma_spec.rb +83 -0
- data/spec/compressor/pbzip2_spec.rb +124 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/bzip2_spec.rb +29 -0
- data/spec/configuration/compressor/gzip_spec.rb +29 -0
- data/spec/configuration/compressor/lzma_spec.rb +29 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +17 -0
- data/spec/configuration/database/mongodb_spec.rb +56 -0
- data/spec/configuration/database/mysql_spec.rb +53 -0
- data/spec/configuration/database/postgresql_spec.rb +53 -0
- data/spec/configuration/database/redis_spec.rb +50 -0
- data/spec/configuration/database/riak_spec.rb +35 -0
- data/spec/configuration/encryptor/gpg_spec.rb +26 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +35 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +32 -0
- data/spec/configuration/notifier/hipchat_spec.rb +44 -0
- data/spec/configuration/notifier/mail_spec.rb +71 -0
- data/spec/configuration/notifier/presently_spec.rb +35 -0
- data/spec/configuration/notifier/prowl_spec.rb +29 -0
- data/spec/configuration/notifier/twitter_spec.rb +35 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +41 -0
- data/spec/configuration/storage/dropbox_spec.rb +38 -0
- data/spec/configuration/storage/ftp_spec.rb +44 -0
- data/spec/configuration/storage/local_spec.rb +29 -0
- data/spec/configuration/storage/ninefold_spec.rb +32 -0
- data/spec/configuration/storage/rsync_spec.rb +41 -0
- data/spec/configuration/storage/s3_spec.rb +38 -0
- data/spec/configuration/storage/scp_spec.rb +41 -0
- data/spec/configuration/storage/sftp_spec.rb +41 -0
- data/spec/configuration/syncer/cloud_files_spec.rb +44 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/push_spec.rb +43 -0
- data/spec/configuration/syncer/s3_spec.rb +38 -0
- data/spec/database/base_spec.rb +54 -0
- data/spec/database/mongodb_spec.rb +428 -0
- data/spec/database/mysql_spec.rb +335 -0
- data/spec/database/postgresql_spec.rb +278 -0
- data/spec/database/redis_spec.rb +260 -0
- data/spec/database/riak_spec.rb +108 -0
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +134 -0
- data/spec/encryptor/open_ssl_spec.rb +129 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/logger_spec.rb +363 -0
- data/spec/model_spec.rb +649 -0
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +199 -0
- data/spec/notifier/hipchat_spec.rb +188 -0
- data/spec/notifier/mail_spec.rb +280 -0
- data/spec/notifier/presently_spec.rb +181 -0
- data/spec/notifier/prowl_spec.rb +117 -0
- data/spec/notifier/twitter_spec.rb +132 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +225 -0
- data/spec/pipeline_spec.rb +257 -0
- data/spec/spec_helper.rb +59 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +160 -0
- data/spec/storage/cloudfiles_spec.rb +230 -0
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +370 -0
- data/spec/storage/ftp_spec.rb +247 -0
- data/spec/storage/local_spec.rb +235 -0
- data/spec/storage/ninefold_spec.rb +319 -0
- data/spec/storage/rsync_spec.rb +345 -0
- data/spec/storage/s3_spec.rb +221 -0
- data/spec/storage/scp_spec.rb +209 -0
- data/spec/storage/sftp_spec.rb +220 -0
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/cloud_files_spec.rb +192 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +192 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +7 -0
- data/templates/cli/utility/compressor/gzip +7 -0
- data/templates/cli/utility/compressor/lzma +7 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -0
- data/templates/cli/utility/database/mongodb +18 -0
- data/templates/cli/utility/database/mysql +21 -0
- data/templates/cli/utility/database/postgresql +17 -0
- data/templates/cli/utility/database/redis +16 -0
- data/templates/cli/utility/database/riak +11 -0
- data/templates/cli/utility/encryptor/gpg +12 -0
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/templates/cli/utility/notifier/campfire +12 -0
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/templates/cli/utility/notifier/mail +22 -0
- data/templates/cli/utility/notifier/presently +13 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/templates/cli/utility/notifier/twitter +13 -0
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloud_files +22 -0
- data/templates/cli/utility/storage/dropbox +20 -0
- data/templates/cli/utility/storage/ftp +12 -0
- data/templates/cli/utility/storage/local +7 -0
- data/templates/cli/utility/storage/ninefold +9 -0
- data/templates/cli/utility/storage/rsync +11 -0
- data/templates/cli/utility/storage/s3 +19 -0
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/templates/cli/utility/syncer/cloud_files +48 -0
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/rsync_pull +17 -0
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/cli/utility/syncer/s3 +45 -0
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +311 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Compressor::Base do
|
6
|
+
let(:base) { Backup::Compressor::Base.new }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'should load defaults' do
|
10
|
+
Backup::Compressor::Base.any_instance.expects(:load_defaults!)
|
11
|
+
base
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#compressor_name' do
|
16
|
+
it 'should return class name with Backup namespace removed' do
|
17
|
+
base.send(:compressor_name).should == 'Compressor::Base'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#log!' do
|
22
|
+
it 'should log a message' do
|
23
|
+
base.expects(:compressor_name).returns('Compressor Name')
|
24
|
+
Backup::Logger.expects(:message).with(
|
25
|
+
'Using Compressor Name for compression.'
|
26
|
+
)
|
27
|
+
base.send(:log!)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Compressor::Bzip2 do
|
6
|
+
let(:compressor) { Backup::Compressor::Bzip2.new }
|
7
|
+
|
8
|
+
describe 'setting configuration defaults' do
|
9
|
+
after { Backup::Configuration::Compressor::Bzip2.clear_defaults! }
|
10
|
+
|
11
|
+
it 'uses and overrides configuration defaults' do
|
12
|
+
Backup::Configuration::Compressor::Bzip2.best.should be_false
|
13
|
+
Backup::Configuration::Compressor::Bzip2.fast.should be_false
|
14
|
+
|
15
|
+
compressor = Backup::Compressor::Bzip2.new
|
16
|
+
compressor.best.should be_false
|
17
|
+
compressor.fast.should be_false
|
18
|
+
|
19
|
+
Backup::Configuration::Compressor::Bzip2.defaults do |c|
|
20
|
+
c.best = true
|
21
|
+
c.fast = true
|
22
|
+
end
|
23
|
+
Backup::Configuration::Compressor::Bzip2.best.should be_true
|
24
|
+
Backup::Configuration::Compressor::Bzip2.fast.should be_true
|
25
|
+
|
26
|
+
compressor = Backup::Compressor::Bzip2.new
|
27
|
+
compressor.best.should be_true
|
28
|
+
compressor.fast.should be_true
|
29
|
+
|
30
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
31
|
+
c.best = false
|
32
|
+
end
|
33
|
+
compressor.best.should be_false
|
34
|
+
compressor.fast.should be_true
|
35
|
+
|
36
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
37
|
+
c.fast = false
|
38
|
+
end
|
39
|
+
compressor.best.should be_true
|
40
|
+
compressor.fast.should be_false
|
41
|
+
end
|
42
|
+
end # describe 'setting configuration defaults'
|
43
|
+
|
44
|
+
describe '#compress_with' do
|
45
|
+
before do
|
46
|
+
compressor.expects(:log!)
|
47
|
+
compressor.expects(:utility).with(:bzip2).returns('bzip2')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should yield with the --best option' do
|
51
|
+
compressor.best = true
|
52
|
+
compressor.compress_with do |cmd, ext|
|
53
|
+
cmd.should == 'bzip2 --best'
|
54
|
+
ext.should == '.bz2'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should yield with the --fast option' do
|
59
|
+
compressor.fast = true
|
60
|
+
compressor.compress_with do |cmd, ext|
|
61
|
+
cmd.should == 'bzip2 --fast'
|
62
|
+
ext.should == '.bz2'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should yield with the --best and --fast options' do
|
67
|
+
compressor.best = true
|
68
|
+
compressor.fast = true
|
69
|
+
compressor.compress_with do |cmd, ext|
|
70
|
+
cmd.should == 'bzip2 --best --fast'
|
71
|
+
ext.should == '.bz2'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should yield with no options' do
|
76
|
+
compressor.compress_with do |cmd, ext|
|
77
|
+
cmd.should == 'bzip2'
|
78
|
+
ext.should == '.bz2'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end # describe '#compress_with'
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Compressor::Gzip do
|
6
|
+
let(:compressor) { Backup::Compressor::Gzip.new }
|
7
|
+
|
8
|
+
describe 'setting configuration defaults' do
|
9
|
+
after { Backup::Configuration::Compressor::Gzip.clear_defaults! }
|
10
|
+
|
11
|
+
it 'uses and overrides configuration defaults' do
|
12
|
+
Backup::Configuration::Compressor::Gzip.best.should be_false
|
13
|
+
Backup::Configuration::Compressor::Gzip.fast.should be_false
|
14
|
+
|
15
|
+
compressor = Backup::Compressor::Gzip.new
|
16
|
+
compressor.best.should be_false
|
17
|
+
compressor.fast.should be_false
|
18
|
+
|
19
|
+
Backup::Configuration::Compressor::Gzip.defaults do |c|
|
20
|
+
c.best = true
|
21
|
+
c.fast = true
|
22
|
+
end
|
23
|
+
Backup::Configuration::Compressor::Gzip.best.should be_true
|
24
|
+
Backup::Configuration::Compressor::Gzip.fast.should be_true
|
25
|
+
|
26
|
+
compressor = Backup::Compressor::Gzip.new
|
27
|
+
compressor.best.should be_true
|
28
|
+
compressor.fast.should be_true
|
29
|
+
|
30
|
+
compressor = Backup::Compressor::Gzip.new do |c|
|
31
|
+
c.best = false
|
32
|
+
end
|
33
|
+
compressor.best.should be_false
|
34
|
+
compressor.fast.should be_true
|
35
|
+
|
36
|
+
compressor = Backup::Compressor::Gzip.new do |c|
|
37
|
+
c.fast = false
|
38
|
+
end
|
39
|
+
compressor.best.should be_true
|
40
|
+
compressor.fast.should be_false
|
41
|
+
end
|
42
|
+
end # describe 'setting configuration defaults'
|
43
|
+
|
44
|
+
describe '#compress_with' do
|
45
|
+
before do
|
46
|
+
compressor.expects(:log!)
|
47
|
+
compressor.expects(:utility).with(:gzip).returns('gzip')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should yield with the --best option' do
|
51
|
+
compressor.best = true
|
52
|
+
compressor.compress_with do |cmd, ext|
|
53
|
+
cmd.should == 'gzip --best'
|
54
|
+
ext.should == '.gz'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should yield with the --fast option' do
|
59
|
+
compressor.fast = true
|
60
|
+
compressor.compress_with do |cmd, ext|
|
61
|
+
cmd.should == 'gzip --fast'
|
62
|
+
ext.should == '.gz'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should yield with the --best and --fast options' do
|
67
|
+
compressor.best = true
|
68
|
+
compressor.fast = true
|
69
|
+
compressor.compress_with do |cmd, ext|
|
70
|
+
cmd.should == 'gzip --best --fast'
|
71
|
+
ext.should == '.gz'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should yield with no options' do
|
76
|
+
compressor.compress_with do |cmd, ext|
|
77
|
+
cmd.should == 'gzip'
|
78
|
+
ext.should == '.gz'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end # describe '#compress_with'
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Compressor::Lzma do
|
6
|
+
let(:compressor) { Backup::Compressor::Lzma.new }
|
7
|
+
|
8
|
+
describe 'setting configuration defaults' do
|
9
|
+
after { Backup::Configuration::Compressor::Lzma.clear_defaults! }
|
10
|
+
|
11
|
+
it 'uses and overrides configuration defaults' do
|
12
|
+
Backup::Configuration::Compressor::Lzma.best.should be_false
|
13
|
+
Backup::Configuration::Compressor::Lzma.fast.should be_false
|
14
|
+
|
15
|
+
compressor = Backup::Compressor::Lzma.new
|
16
|
+
compressor.best.should be_false
|
17
|
+
compressor.fast.should be_false
|
18
|
+
|
19
|
+
Backup::Configuration::Compressor::Lzma.defaults do |c|
|
20
|
+
c.best = true
|
21
|
+
c.fast = true
|
22
|
+
end
|
23
|
+
Backup::Configuration::Compressor::Lzma.best.should be_true
|
24
|
+
Backup::Configuration::Compressor::Lzma.fast.should be_true
|
25
|
+
|
26
|
+
compressor = Backup::Compressor::Lzma.new
|
27
|
+
compressor.best.should be_true
|
28
|
+
compressor.fast.should be_true
|
29
|
+
|
30
|
+
compressor = Backup::Compressor::Lzma.new do |c|
|
31
|
+
c.best = false
|
32
|
+
end
|
33
|
+
compressor.best.should be_false
|
34
|
+
compressor.fast.should be_true
|
35
|
+
|
36
|
+
compressor = Backup::Compressor::Lzma.new do |c|
|
37
|
+
c.fast = false
|
38
|
+
end
|
39
|
+
compressor.best.should be_true
|
40
|
+
compressor.fast.should be_false
|
41
|
+
end
|
42
|
+
end # describe 'setting configuration defaults'
|
43
|
+
|
44
|
+
describe '#compress_with' do
|
45
|
+
before do
|
46
|
+
compressor.expects(:log!)
|
47
|
+
compressor.expects(:utility).with(:lzma).returns('lzma')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should yield with the --best option' do
|
51
|
+
compressor.best = true
|
52
|
+
compressor.compress_with do |cmd, ext|
|
53
|
+
cmd.should == 'lzma --best'
|
54
|
+
ext.should == '.lzma'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should yield with the --fast option' do
|
59
|
+
compressor.fast = true
|
60
|
+
compressor.compress_with do |cmd, ext|
|
61
|
+
cmd.should == 'lzma --fast'
|
62
|
+
ext.should == '.lzma'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should yield with the --best and --fast options' do
|
67
|
+
compressor.best = true
|
68
|
+
compressor.fast = true
|
69
|
+
compressor.compress_with do |cmd, ext|
|
70
|
+
cmd.should == 'lzma --best --fast'
|
71
|
+
ext.should == '.lzma'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should yield with no options' do
|
76
|
+
compressor.compress_with do |cmd, ext|
|
77
|
+
cmd.should == 'lzma'
|
78
|
+
ext.should == '.lzma'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end # describe '#compress_with'
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Compressor::Pbzip2 do
|
6
|
+
let(:compressor) { Backup::Compressor::Pbzip2.new }
|
7
|
+
|
8
|
+
describe 'setting configuration defaults' do
|
9
|
+
after { Backup::Configuration::Compressor::Pbzip2.clear_defaults! }
|
10
|
+
|
11
|
+
it 'uses and overrides configuration defaults' do
|
12
|
+
Backup::Configuration::Compressor::Pbzip2.best.should be_false
|
13
|
+
Backup::Configuration::Compressor::Pbzip2.fast.should be_false
|
14
|
+
Backup::Configuration::Compressor::Pbzip2.processors.should be_false
|
15
|
+
|
16
|
+
compressor = Backup::Compressor::Pbzip2.new
|
17
|
+
compressor.best.should be_false
|
18
|
+
compressor.fast.should be_false
|
19
|
+
compressor.processors.should be_false
|
20
|
+
|
21
|
+
Backup::Configuration::Compressor::Pbzip2.defaults do |c|
|
22
|
+
c.best = true
|
23
|
+
c.fast = true
|
24
|
+
c.processors = 2
|
25
|
+
end
|
26
|
+
Backup::Configuration::Compressor::Pbzip2.best.should be_true
|
27
|
+
Backup::Configuration::Compressor::Pbzip2.fast.should be_true
|
28
|
+
Backup::Configuration::Compressor::Pbzip2.processors.should == 2
|
29
|
+
|
30
|
+
compressor = Backup::Compressor::Pbzip2.new
|
31
|
+
compressor.best.should be_true
|
32
|
+
compressor.fast.should be_true
|
33
|
+
compressor.processors.should == 2
|
34
|
+
|
35
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
36
|
+
c.best = false
|
37
|
+
end
|
38
|
+
compressor.best.should be_false
|
39
|
+
compressor.fast.should be_true
|
40
|
+
compressor.processors.should == 2
|
41
|
+
|
42
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
43
|
+
c.fast = false
|
44
|
+
end
|
45
|
+
compressor.best.should be_true
|
46
|
+
compressor.fast.should be_false
|
47
|
+
compressor.processors.should == 2
|
48
|
+
|
49
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
50
|
+
c.processors = false
|
51
|
+
end
|
52
|
+
compressor.best.should be_true
|
53
|
+
compressor.fast.should be_true
|
54
|
+
compressor.processors.should be_false
|
55
|
+
end
|
56
|
+
end # describe 'setting configuration defaults'
|
57
|
+
|
58
|
+
describe '#compress_with' do
|
59
|
+
before do
|
60
|
+
compressor.expects(:log!)
|
61
|
+
compressor.expects(:utility).with(:pbzip2).returns('pbzip2')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should yield with the --best option' do
|
65
|
+
compressor.best = true
|
66
|
+
compressor.compress_with do |cmd, ext|
|
67
|
+
cmd.should == 'pbzip2 --best'
|
68
|
+
ext.should == '.bz2'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should yield with the --fast option' do
|
73
|
+
compressor.fast = true
|
74
|
+
compressor.compress_with do |cmd, ext|
|
75
|
+
cmd.should == 'pbzip2 --fast'
|
76
|
+
ext.should == '.bz2'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should yield with the -p option' do
|
81
|
+
compressor.processors = 2
|
82
|
+
compressor.compress_with do |cmd, ext|
|
83
|
+
cmd.should == 'pbzip2 -p2'
|
84
|
+
ext.should == '.bz2'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should yield with the --best and --fast options' do
|
89
|
+
compressor.best = true
|
90
|
+
compressor.fast = true
|
91
|
+
compressor.compress_with do |cmd, ext|
|
92
|
+
cmd.should == 'pbzip2 --best --fast'
|
93
|
+
ext.should == '.bz2'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should yield with the --best and -p options' do
|
98
|
+
compressor.best = true
|
99
|
+
compressor.processors = 2
|
100
|
+
compressor.compress_with do |cmd, ext|
|
101
|
+
cmd.should == 'pbzip2 --best -p2'
|
102
|
+
ext.should == '.bz2'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should yield with the --fast and -p options' do
|
107
|
+
compressor.fast = true
|
108
|
+
compressor.processors = 2
|
109
|
+
compressor.compress_with do |cmd, ext|
|
110
|
+
cmd.should == 'pbzip2 --fast -p2'
|
111
|
+
ext.should == '.bz2'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should yield with no options' do
|
116
|
+
compressor.compress_with do |cmd, ext|
|
117
|
+
cmd.should == 'pbzip2'
|
118
|
+
ext.should == '.bz2'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end # describe '#compress_with'
|
123
|
+
|
124
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,321 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Backup::Config' do
|
6
|
+
let(:config) { Backup::Config }
|
7
|
+
before(:all) { config.send(:reset!) }
|
8
|
+
after(:each) do
|
9
|
+
config.unstub(:update)
|
10
|
+
config.unstub(:set_root_path)
|
11
|
+
config.unstub(:set_path_variable)
|
12
|
+
config.send(:reset!)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#update' do
|
16
|
+
let(:default_root_path) { config.root_path }
|
17
|
+
|
18
|
+
context 'when a root_path is given' do
|
19
|
+
it 'should use #set_root_path to set the new root_path' do
|
20
|
+
config.expects(:set_root_path).with('a/path')
|
21
|
+
|
22
|
+
config.update(:root_path => 'a/path')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should set all paths using the new root_path' do
|
26
|
+
config.expects(:set_root_path).with('path').returns('/root/path')
|
27
|
+
Backup::Config::DEFAULTS.each do |key, val|
|
28
|
+
config.expects(:set_path_variable).with(key, nil, val, '/root/path')
|
29
|
+
end
|
30
|
+
|
31
|
+
config.update(:root_path => 'path')
|
32
|
+
end
|
33
|
+
end # context 'when a root_path is given'
|
34
|
+
|
35
|
+
context 'when a root_path is not given' do
|
36
|
+
it 'should set all paths without using a root_path' do
|
37
|
+
Backup::Config::DEFAULTS.each do |key, val|
|
38
|
+
config.expects(:set_path_variable).with(key, nil, val, false)
|
39
|
+
end
|
40
|
+
|
41
|
+
config.update
|
42
|
+
end
|
43
|
+
end # context 'when a root_path is not given'
|
44
|
+
|
45
|
+
end # describe '#update'
|
46
|
+
|
47
|
+
describe '#load_config!' do
|
48
|
+
context 'when @config_file exists' do
|
49
|
+
before do
|
50
|
+
File.expects(:exist?).with(config.config_file).returns(true)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should load the config file' do
|
54
|
+
File.expects(:read).with(config.config_file).returns(:file_contents)
|
55
|
+
config.expects(:module_eval).with(:file_contents, config.config_file)
|
56
|
+
|
57
|
+
expect do
|
58
|
+
config.load_config!
|
59
|
+
end.not_to raise_error
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when @config_file does not exist' do
|
64
|
+
before do
|
65
|
+
File.expects(:exist?).returns(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should raise an error' do
|
69
|
+
File.expects(:read).never
|
70
|
+
config.expects(:module_eval).never
|
71
|
+
|
72
|
+
expect do
|
73
|
+
config.load_config!
|
74
|
+
end.to raise_error {|err|
|
75
|
+
err.should be_an_instance_of Backup::Errors::Config::NotFoundError
|
76
|
+
err.message.should match(
|
77
|
+
/Could not find configuration file: '#{config.config_file}'/
|
78
|
+
)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end # describe '#load_config!'
|
83
|
+
|
84
|
+
describe '#set_root_path' do
|
85
|
+
|
86
|
+
context 'when the given path == @root_path' do
|
87
|
+
it 'should return @root_path without requiring the path to exist' do
|
88
|
+
File.expects(:directory?).never
|
89
|
+
expect do
|
90
|
+
config.send(:set_root_path, config.root_path).
|
91
|
+
should == config.root_path
|
92
|
+
end.not_to raise_error
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when the given path exists' do
|
97
|
+
it 'should set and return the @root_path' do
|
98
|
+
expect do
|
99
|
+
config.send(:set_root_path, Dir.pwd).should == Dir.pwd
|
100
|
+
end.not_to raise_error
|
101
|
+
config.root_path.should == Dir.pwd
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should expand relative paths' do
|
105
|
+
expect do
|
106
|
+
config.send(:set_root_path, '').should == Dir.pwd
|
107
|
+
end.not_to raise_error
|
108
|
+
config.root_path.should == Dir.pwd
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'when the given path does not exist' do
|
113
|
+
it 'should raise an error' do
|
114
|
+
path = File.expand_path('foo')
|
115
|
+
expect do
|
116
|
+
config.send(:set_root_path, 'foo')
|
117
|
+
end.to raise_error {|err|
|
118
|
+
err.should be_an_instance_of Backup::Errors::Config::NotFoundError
|
119
|
+
err.message.should match(/Root Path Not Found/)
|
120
|
+
err.message.should match(/Path was: #{ path }/)
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end # describe '#set_root_path'
|
126
|
+
|
127
|
+
describe '#set_path_variable' do
|
128
|
+
after do
|
129
|
+
if config.instance_variable_defined?(:@var)
|
130
|
+
config.send(:remove_instance_variable, :@var)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'when a path is given' do
|
135
|
+
context 'when the given path is an absolute path' do
|
136
|
+
it 'should always use the given path' do
|
137
|
+
path = File.expand_path('foo')
|
138
|
+
|
139
|
+
config.send(:set_path_variable, 'var', path, 'none', '/root/path')
|
140
|
+
config.instance_variable_get(:@var).should == path
|
141
|
+
|
142
|
+
config.send(:set_path_variable, 'var', path, 'none', nil)
|
143
|
+
config.instance_variable_get(:@var).should == path
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when the given path is a relative path' do
|
148
|
+
context 'when a root_path is given' do
|
149
|
+
it 'should append the path to the root_path' do
|
150
|
+
config.send(:set_path_variable, 'var', 'foo', 'none', '/root/path')
|
151
|
+
config.instance_variable_get(:@var).should == '/root/path/foo'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
context 'when a root_path is not given' do
|
155
|
+
it 'should expand the path' do
|
156
|
+
path = File.expand_path('foo')
|
157
|
+
|
158
|
+
config.send(:set_path_variable, 'var', 'foo', 'none', false)
|
159
|
+
config.instance_variable_get(:@var).should == path
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end # context 'when a path is given'
|
164
|
+
|
165
|
+
context 'when no path is given' do
|
166
|
+
context 'when a root_path is given' do
|
167
|
+
it 'should use the root_path with the given ending' do
|
168
|
+
config.send(:set_path_variable, 'var', nil, 'ending', '/root/path')
|
169
|
+
config.instance_variable_get(:@var).should == '/root/path/ending'
|
170
|
+
end
|
171
|
+
end
|
172
|
+
context 'when a root_path is not given' do
|
173
|
+
it 'should do nothing' do
|
174
|
+
config.send(:set_path_variable, 'var', nil, 'ending', false)
|
175
|
+
config.instance_variable_defined?(:@var).should be_false
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end # context 'when no path is given'
|
179
|
+
|
180
|
+
end # describe '#set_path_variable'
|
181
|
+
|
182
|
+
describe '#reset!' do
|
183
|
+
before do
|
184
|
+
@env_user = ENV['USER']
|
185
|
+
@env_home = ENV['HOME']
|
186
|
+
end
|
187
|
+
|
188
|
+
after do
|
189
|
+
ENV['USER'] = @env_user
|
190
|
+
ENV['HOME'] = @env_home
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should be called to set variables when module is loaded' do
|
194
|
+
# just to avoid 'already initialized constant' warnings
|
195
|
+
config.constants.each {|const| config.send(:remove_const, const) }
|
196
|
+
|
197
|
+
expected = config.instance_variables.sort.map(&:to_sym) - [:@mocha]
|
198
|
+
config.instance_variables.each do |var|
|
199
|
+
config.send(:remove_instance_variable, var)
|
200
|
+
end
|
201
|
+
config.instance_variables.should be_empty
|
202
|
+
|
203
|
+
load File.expand_path('../../lib/backup/config.rb', __FILE__)
|
204
|
+
config.instance_variables.sort.map(&:to_sym).should == expected
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'when setting @user' do
|
208
|
+
context 'when ENV["USER"] is set' do
|
209
|
+
before { ENV['USER'] = 'test' }
|
210
|
+
|
211
|
+
it 'should set value for @user to ENV["USER"]' do
|
212
|
+
config.send(:reset!)
|
213
|
+
config.user.should == 'test'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context 'when ENV["USER"] is not set' do
|
218
|
+
before { ENV.delete('USER') }
|
219
|
+
|
220
|
+
it 'should set value using the user login name' do
|
221
|
+
config.send(:reset!)
|
222
|
+
config.user.should == Etc.getpwuid.name
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end # context 'when setting @user'
|
226
|
+
|
227
|
+
context 'when setting @root_path' do
|
228
|
+
context 'when ENV["HOME"] is set' do
|
229
|
+
before { ENV['HOME'] = 'test/home/dir' }
|
230
|
+
|
231
|
+
it 'should set value using ENV["HOME"]' do
|
232
|
+
config.send(:reset!)
|
233
|
+
config.root_path.should ==
|
234
|
+
File.join(File.expand_path('test/home/dir'),'Backup')
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context 'when ENV["HOME"] is not set' do
|
239
|
+
before { ENV.delete('HOME') }
|
240
|
+
|
241
|
+
it 'should set value using $PWD' do
|
242
|
+
config.send(:reset!)
|
243
|
+
config.root_path.should == File.expand_path('Backup')
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end # context 'when setting @root_path'
|
247
|
+
|
248
|
+
context 'when setting other path variables' do
|
249
|
+
before { ENV['HOME'] = 'test/home/dir' }
|
250
|
+
|
251
|
+
it 'should use #update' do
|
252
|
+
config.expects(:update).with(
|
253
|
+
:root_path => File.join(File.expand_path('test/home/dir'),'Backup')
|
254
|
+
)
|
255
|
+
config.send(:reset!)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
end # describe '#reset!'
|
260
|
+
|
261
|
+
describe '#add_dsl_constants!' do
|
262
|
+
it 'should be called when the module is loaded' do
|
263
|
+
config.constants.each {|const| config.send(:remove_const, const) }
|
264
|
+
config.constants.should be_empty
|
265
|
+
|
266
|
+
load File.expand_path('../../lib/backup/config.rb', __FILE__)
|
267
|
+
|
268
|
+
Backup::Config.const_defined?('MySQL').should be_true
|
269
|
+
Backup::Config.const_defined?('RSync').should be_true
|
270
|
+
Backup::Config::RSync.const_defined?('Local').should be_true
|
271
|
+
end
|
272
|
+
end # describe '#add_dsl_constants!'
|
273
|
+
|
274
|
+
describe '#create_modules' do
|
275
|
+
module TestScope; end
|
276
|
+
|
277
|
+
context 'when given an array of constant names' do
|
278
|
+
it 'should create modules for the given scope' do
|
279
|
+
config.send(:create_modules, TestScope, ['Foo', 'Bar'])
|
280
|
+
TestScope.const_defined?('Foo').should be_true
|
281
|
+
TestScope.const_defined?('Bar').should be_true
|
282
|
+
TestScope::Foo.class.should == Module
|
283
|
+
TestScope::Bar.class.should == Module
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context 'when the given array contains Hash values' do
|
288
|
+
it 'should create deeply nested modules' do
|
289
|
+
config.send(
|
290
|
+
:create_modules,
|
291
|
+
TestScope,
|
292
|
+
[ 'FooBar', {
|
293
|
+
:LevelA => [ 'NameA', {
|
294
|
+
:LevelB => ['NameB']
|
295
|
+
} ]
|
296
|
+
} ]
|
297
|
+
)
|
298
|
+
TestScope.const_defined?('FooBar').should be_true
|
299
|
+
TestScope.const_defined?('LevelA').should be_true
|
300
|
+
TestScope::LevelA.const_defined?('NameA').should be_true
|
301
|
+
TestScope::LevelA.const_defined?('LevelB').should be_true
|
302
|
+
TestScope::LevelA::LevelB.const_defined?('NameB').should be_true
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
describe 'Backup.const_missing' do
|
308
|
+
it 'should warn if Backup::CONFIG_FILE is referenced from an older config.rb' do
|
309
|
+
Backup::Logger.expects(:warn)
|
310
|
+
expect do
|
311
|
+
Backup.const_get('CONFIG_FILE').should == Backup::Config.config_file
|
312
|
+
end.not_to raise_error
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'should still handle other missing constants' do
|
316
|
+
expect do
|
317
|
+
Backup.const_get('FOO')
|
318
|
+
end.to raise_error(NameError, 'uninitialized constant Backup::FOO')
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|