backup 3.0.23 → 3.0.24
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +42 -45
- data/Guardfile +7 -4
- data/README.md +10 -7
- data/backup.gemspec +2 -2
- data/lib/backup.rb +27 -97
- data/lib/backup/archive.rb +14 -6
- data/lib/backup/cli/helpers.rb +52 -49
- data/lib/backup/cli/utility.rb +9 -1
- data/lib/backup/compressor/base.rb +10 -4
- data/lib/backup/compressor/bzip2.rb +22 -26
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +22 -23
- data/lib/backup/compressor/lzma.rb +15 -13
- data/lib/backup/compressor/pbzip2.rb +20 -17
- data/lib/backup/config.rb +6 -3
- data/lib/backup/configuration.rb +33 -0
- data/lib/backup/configuration/helpers.rb +114 -28
- data/lib/backup/configuration/store.rb +24 -0
- data/lib/backup/database/base.rb +0 -6
- data/lib/backup/database/mongodb.rb +27 -11
- data/lib/backup/database/mysql.rb +19 -14
- data/lib/backup/database/postgresql.rb +16 -11
- data/lib/backup/database/redis.rb +7 -11
- data/lib/backup/database/riak.rb +3 -6
- data/lib/backup/dependency.rb +5 -11
- data/lib/backup/model.rb +14 -5
- data/lib/backup/notifier/campfire.rb +3 -16
- data/lib/backup/notifier/hipchat.rb +1 -7
- data/lib/backup/notifier/mail.rb +1 -1
- data/lib/backup/packager.rb +29 -19
- data/lib/backup/pipeline.rb +110 -0
- data/lib/backup/storage/dropbox.rb +4 -7
- data/lib/backup/syncer/base.rb +8 -4
- data/lib/backup/syncer/cloud/base.rb +247 -0
- data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
- data/lib/backup/syncer/cloud/s3.rb +68 -0
- data/lib/backup/syncer/rsync/base.rb +1 -4
- data/lib/backup/syncer/rsync/local.rb +9 -5
- data/lib/backup/syncer/rsync/pull.rb +1 -1
- data/lib/backup/syncer/rsync/push.rb +10 -5
- data/lib/backup/version.rb +1 -1
- data/spec-live/.gitignore +6 -0
- data/spec-live/README +7 -0
- data/spec-live/backups/config.rb +153 -0
- data/spec-live/backups/config.yml.template +43 -0
- data/spec-live/compressor/custom_spec.rb +30 -0
- data/spec-live/compressor/gzip_spec.rb +30 -0
- data/spec-live/notifier/mail_spec.rb +85 -0
- data/spec-live/spec_helper.rb +85 -0
- data/spec-live/storage/dropbox_spec.rb +151 -0
- data/spec-live/storage/local_spec.rb +83 -0
- data/spec-live/storage/scp_spec.rb +193 -0
- data/spec-live/syncer/cloud/s3_spec.rb +124 -0
- data/spec/archive_spec.rb +86 -31
- data/spec/cleaner_spec.rb +8 -0
- data/spec/cli/helpers_spec.rb +200 -75
- data/spec/cli/utility_spec.rb +11 -3
- data/spec/compressor/base_spec.rb +31 -10
- data/spec/compressor/bzip2_spec.rb +212 -57
- data/spec/compressor/custom_spec.rb +106 -0
- data/spec/compressor/gzip_spec.rb +212 -57
- data/spec/compressor/lzma_spec.rb +75 -35
- data/spec/compressor/pbzip2_spec.rb +93 -52
- data/spec/configuration/helpers_spec.rb +406 -0
- data/spec/configuration/store_spec.rb +39 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/database/base_spec.rb +19 -10
- data/spec/database/mongodb_spec.rb +195 -70
- data/spec/database/mysql_spec.rb +183 -64
- data/spec/database/postgresql_spec.rb +167 -53
- data/spec/database/redis_spec.rb +121 -46
- data/spec/database/riak_spec.rb +96 -27
- data/spec/dependency_spec.rb +2 -0
- data/spec/encryptor/base_spec.rb +10 -0
- data/spec/encryptor/gpg_spec.rb +29 -13
- data/spec/encryptor/open_ssl_spec.rb +40 -21
- data/spec/logger_spec.rb +4 -0
- data/spec/model_spec.rb +19 -2
- data/spec/notifier/base_spec.rb +32 -17
- data/spec/notifier/campfire_spec.rb +63 -45
- data/spec/notifier/hipchat_spec.rb +79 -56
- data/spec/notifier/mail_spec.rb +82 -46
- data/spec/notifier/prowl_spec.rb +53 -32
- data/spec/notifier/twitter_spec.rb +62 -41
- data/spec/packager_spec.rb +95 -36
- data/spec/pipeline_spec.rb +259 -0
- data/spec/spec_helper.rb +6 -5
- data/spec/storage/base_spec.rb +61 -41
- data/spec/storage/cloudfiles_spec.rb +69 -45
- data/spec/storage/dropbox_spec.rb +158 -36
- data/spec/storage/ftp_spec.rb +69 -45
- data/spec/storage/local_spec.rb +47 -23
- data/spec/storage/ninefold_spec.rb +55 -31
- data/spec/storage/rsync_spec.rb +67 -50
- data/spec/storage/s3_spec.rb +65 -41
- data/spec/storage/scp_spec.rb +65 -41
- data/spec/storage/sftp_spec.rb +65 -41
- data/spec/syncer/base_spec.rb +91 -4
- data/spec/syncer/cloud/base_spec.rb +511 -0
- data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
- data/spec/syncer/cloud/s3_spec.rb +174 -0
- data/spec/syncer/rsync/base_spec.rb +46 -66
- data/spec/syncer/rsync/local_spec.rb +55 -26
- data/spec/syncer/rsync/pull_spec.rb +15 -4
- data/spec/syncer/rsync/push_spec.rb +59 -52
- data/templates/cli/utility/compressor/bzip2 +1 -4
- data/templates/cli/utility/compressor/custom +11 -0
- data/templates/cli/utility/compressor/gzip +1 -4
- data/templates/cli/utility/compressor/lzma +3 -0
- data/templates/cli/utility/compressor/pbzip2 +3 -0
- data/templates/cli/utility/database/mysql +4 -1
- data/templates/cli/utility/syncer/cloud_files +17 -19
- data/templates/cli/utility/syncer/s3 +18 -20
- metadata +38 -92
- data/lib/backup/configuration/base.rb +0 -15
- data/lib/backup/configuration/compressor/base.rb +0 -9
- data/lib/backup/configuration/compressor/bzip2.rb +0 -23
- data/lib/backup/configuration/compressor/gzip.rb +0 -23
- data/lib/backup/configuration/compressor/lzma.rb +0 -23
- data/lib/backup/configuration/compressor/pbzip2.rb +0 -28
- data/lib/backup/configuration/database/base.rb +0 -19
- data/lib/backup/configuration/database/mongodb.rb +0 -49
- data/lib/backup/configuration/database/mysql.rb +0 -42
- data/lib/backup/configuration/database/postgresql.rb +0 -41
- data/lib/backup/configuration/database/redis.rb +0 -39
- data/lib/backup/configuration/database/riak.rb +0 -29
- data/lib/backup/configuration/encryptor/base.rb +0 -9
- data/lib/backup/configuration/encryptor/gpg.rb +0 -17
- data/lib/backup/configuration/encryptor/open_ssl.rb +0 -32
- data/lib/backup/configuration/notifier/base.rb +0 -28
- data/lib/backup/configuration/notifier/campfire.rb +0 -25
- data/lib/backup/configuration/notifier/hipchat.rb +0 -41
- data/lib/backup/configuration/notifier/mail.rb +0 -112
- data/lib/backup/configuration/notifier/presently.rb +0 -25
- data/lib/backup/configuration/notifier/prowl.rb +0 -23
- data/lib/backup/configuration/notifier/twitter.rb +0 -21
- data/lib/backup/configuration/storage/base.rb +0 -18
- data/lib/backup/configuration/storage/cloudfiles.rb +0 -25
- data/lib/backup/configuration/storage/dropbox.rb +0 -58
- data/lib/backup/configuration/storage/ftp.rb +0 -29
- data/lib/backup/configuration/storage/local.rb +0 -17
- data/lib/backup/configuration/storage/ninefold.rb +0 -20
- data/lib/backup/configuration/storage/rsync.rb +0 -29
- data/lib/backup/configuration/storage/s3.rb +0 -25
- data/lib/backup/configuration/storage/scp.rb +0 -25
- data/lib/backup/configuration/storage/sftp.rb +0 -25
- data/lib/backup/configuration/syncer/base.rb +0 -10
- data/lib/backup/configuration/syncer/cloud.rb +0 -23
- data/lib/backup/configuration/syncer/cloud_files.rb +0 -30
- data/lib/backup/configuration/syncer/rsync/base.rb +0 -28
- data/lib/backup/configuration/syncer/rsync/local.rb +0 -11
- data/lib/backup/configuration/syncer/rsync/pull.rb +0 -11
- data/lib/backup/configuration/syncer/rsync/push.rb +0 -31
- data/lib/backup/configuration/syncer/s3.rb +0 -23
- data/lib/backup/notifier/presently.rb +0 -88
- data/lib/backup/syncer/cloud.rb +0 -187
- data/lib/backup/syncer/cloud_files.rb +0 -56
- data/lib/backup/syncer/s3.rb +0 -47
- data/spec/configuration/base_spec.rb +0 -35
- data/spec/configuration/compressor/bzip2_spec.rb +0 -29
- data/spec/configuration/compressor/gzip_spec.rb +0 -29
- data/spec/configuration/compressor/lzma_spec.rb +0 -29
- data/spec/configuration/compressor/pbzip2_spec.rb +0 -32
- data/spec/configuration/database/base_spec.rb +0 -17
- data/spec/configuration/database/mongodb_spec.rb +0 -56
- data/spec/configuration/database/mysql_spec.rb +0 -53
- data/spec/configuration/database/postgresql_spec.rb +0 -53
- data/spec/configuration/database/redis_spec.rb +0 -50
- data/spec/configuration/database/riak_spec.rb +0 -35
- data/spec/configuration/encryptor/gpg_spec.rb +0 -26
- data/spec/configuration/encryptor/open_ssl_spec.rb +0 -35
- data/spec/configuration/notifier/base_spec.rb +0 -32
- data/spec/configuration/notifier/campfire_spec.rb +0 -32
- data/spec/configuration/notifier/hipchat_spec.rb +0 -44
- data/spec/configuration/notifier/mail_spec.rb +0 -71
- data/spec/configuration/notifier/presently_spec.rb +0 -35
- data/spec/configuration/notifier/prowl_spec.rb +0 -29
- data/spec/configuration/notifier/twitter_spec.rb +0 -35
- data/spec/configuration/storage/cloudfiles_spec.rb +0 -41
- data/spec/configuration/storage/dropbox_spec.rb +0 -38
- data/spec/configuration/storage/ftp_spec.rb +0 -44
- data/spec/configuration/storage/local_spec.rb +0 -29
- data/spec/configuration/storage/ninefold_spec.rb +0 -32
- data/spec/configuration/storage/rsync_spec.rb +0 -41
- data/spec/configuration/storage/s3_spec.rb +0 -38
- data/spec/configuration/storage/scp_spec.rb +0 -41
- data/spec/configuration/storage/sftp_spec.rb +0 -41
- data/spec/configuration/syncer/cloud_files_spec.rb +0 -44
- data/spec/configuration/syncer/rsync/base_spec.rb +0 -33
- data/spec/configuration/syncer/rsync/local_spec.rb +0 -10
- data/spec/configuration/syncer/rsync/pull_spec.rb +0 -10
- data/spec/configuration/syncer/rsync/push_spec.rb +0 -43
- data/spec/configuration/syncer/s3_spec.rb +0 -38
- data/spec/notifier/presently_spec.rb +0 -181
- data/spec/syncer/cloud_files_spec.rb +0 -192
- data/spec/syncer/s3_spec.rb +0 -192
- data/templates/cli/utility/notifier/presently +0 -13
data/spec/cli/utility_spec.rb
CHANGED
@@ -86,6 +86,10 @@ describe 'Backup::CLI::Utility' do
|
|
86
86
|
FileUtils.unstub(:touch)
|
87
87
|
end
|
88
88
|
|
89
|
+
after do
|
90
|
+
Backup::Config.send(:reset!)
|
91
|
+
end
|
92
|
+
|
89
93
|
context 'when given a config_path' do
|
90
94
|
context 'when no config file exists' do
|
91
95
|
it 'should create both a config and a model under the given path' do
|
@@ -190,8 +194,8 @@ describe 'Backup::CLI::Utility' do
|
|
190
194
|
[--storages=STORAGES] # (cloud_files, dropbox, ftp, local, ninefold, rsync, s3, scp, sftp)
|
191
195
|
[--syncers=SYNCERS] # (cloud_files, rsync_local, rsync_pull, rsync_push, s3)
|
192
196
|
[--encryptors=ENCRYPTORS] # (gpg, openssl)
|
193
|
-
[--compressors=COMPRESSORS] # (bzip2, gzip, lzma, pbzip2)
|
194
|
-
[--notifiers=NOTIFIERS] # (campfire, hipchat, mail,
|
197
|
+
[--compressors=COMPRESSORS] # (bzip2, custom, gzip, lzma, pbzip2)
|
198
|
+
[--notifiers=NOTIFIERS] # (campfire, hipchat, mail, prowl, twitter)
|
195
199
|
[--archives]
|
196
200
|
[--splitter] # use `--no-splitter` to disable
|
197
201
|
# Default: true
|
@@ -213,7 +217,7 @@ describe 'Backup::CLI::Utility' do
|
|
213
217
|
|
214
218
|
output_lines.sort.should == expected_lines.sort
|
215
219
|
end
|
216
|
-
end
|
220
|
+
end # describe '#generate:model'
|
217
221
|
|
218
222
|
describe '#generate:config' do
|
219
223
|
before do
|
@@ -221,6 +225,10 @@ describe 'Backup::CLI::Utility' do
|
|
221
225
|
FileUtils.unstub(:touch)
|
222
226
|
end
|
223
227
|
|
228
|
+
after do
|
229
|
+
Backup::Config.send(:reset!)
|
230
|
+
end
|
231
|
+
|
224
232
|
context 'when given a config_path' do
|
225
233
|
it 'should create a config file in the given path' do
|
226
234
|
Dir.mktmpdir do |path|
|
@@ -3,29 +3,50 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Compressor::Base do
|
6
|
-
let(:
|
6
|
+
let(:compressor) { Backup::Compressor::Base.new }
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
Backup::
|
11
|
-
|
8
|
+
it 'should include CLI::Helpers' do
|
9
|
+
Backup::Compressor::Base.
|
10
|
+
include?(Backup::CLI::Helpers).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should include Configuration::Helpers' do
|
14
|
+
Backup::Compressor::Base.
|
15
|
+
include?(Backup::Configuration::Helpers).should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#compress_with' do
|
19
|
+
it 'should yield the compressor command and extension' do
|
20
|
+
compressor.instance_variable_set(:@cmd, 'compressor command')
|
21
|
+
compressor.instance_variable_set(:@ext, 'compressor extension')
|
22
|
+
|
23
|
+
compressor.expects(:log!)
|
24
|
+
|
25
|
+
compressor.compress_with do |cmd, ext|
|
26
|
+
cmd.should == 'compressor command'
|
27
|
+
ext.should == 'compressor extension'
|
28
|
+
end
|
12
29
|
end
|
13
30
|
end
|
14
31
|
|
15
32
|
describe '#compressor_name' do
|
16
33
|
it 'should return class name with Backup namespace removed' do
|
17
|
-
|
34
|
+
compressor.send(:compressor_name).should == 'Compressor::Base'
|
18
35
|
end
|
19
36
|
end
|
20
37
|
|
21
38
|
describe '#log!' do
|
22
39
|
it 'should log a message' do
|
23
|
-
|
40
|
+
compressor.instance_variable_set(:@cmd, 'compressor command')
|
41
|
+
compressor.instance_variable_set(:@ext, 'compressor extension')
|
42
|
+
compressor.expects(:compressor_name).returns('Compressor Name')
|
43
|
+
|
24
44
|
Backup::Logger.expects(:message).with(
|
25
|
-
|
45
|
+
"Using Compressor Name for compression.\n" +
|
46
|
+
" Command: 'compressor command'\n" +
|
47
|
+
" Ext: 'compressor extension'"
|
26
48
|
)
|
27
|
-
|
49
|
+
compressor.send(:log!)
|
28
50
|
end
|
29
51
|
end
|
30
|
-
|
31
52
|
end
|
@@ -3,81 +3,236 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Compressor::Bzip2 do
|
6
|
-
|
6
|
+
before do
|
7
|
+
Backup::Compressor::Bzip2.any_instance.stubs(:utility).returns('bzip2')
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
it 'should be a subclass of Compressor::Base' do
|
11
|
+
Backup::Compressor::Bzip2.
|
12
|
+
superclass.should == Backup::Compressor::Base
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
Backup::Configuration::Compressor::Bzip2.fast.should be_false
|
15
|
+
describe '#initialize' do
|
16
|
+
let(:compressor) { Backup::Compressor::Bzip2.new }
|
14
17
|
|
15
|
-
|
16
|
-
compressor.best.should be_false
|
17
|
-
compressor.fast.should be_false
|
18
|
+
after { Backup::Compressor::Bzip2.clear_defaults! }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
it 'should load pre-configured defaults' do
|
21
|
+
Backup::Compressor::Bzip2.any_instance.expects(:load_defaults!)
|
22
|
+
compressor
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when no pre-configured defaults have been set' do
|
26
|
+
it 'should use default values' do
|
27
|
+
compressor.level.should be_false
|
28
|
+
|
29
|
+
compressor.instance_variable_get(:@cmd).should == 'bzip2'
|
30
|
+
compressor.instance_variable_get(:@ext).should == '.bz2'
|
22
31
|
end
|
23
|
-
Backup::Configuration::Compressor::Bzip2.best.should be_true
|
24
|
-
Backup::Configuration::Compressor::Bzip2.fast.should be_true
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
33
|
+
it 'should use the values given' do
|
34
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
35
|
+
c.level = 5
|
36
|
+
end
|
37
|
+
compressor.level.should == 5
|
29
38
|
|
30
|
-
|
31
|
-
|
39
|
+
compressor.instance_variable_get(:@cmd).should == 'bzip2 -5'
|
40
|
+
compressor.instance_variable_get(:@ext).should == '.bz2'
|
32
41
|
end
|
33
|
-
|
34
|
-
compressor.fast.should be_true
|
42
|
+
end # context 'when no pre-configured defaults have been set'
|
35
43
|
|
36
|
-
|
37
|
-
|
44
|
+
context 'when pre-configured defaults have been set' do
|
45
|
+
before do
|
46
|
+
Backup::Compressor::Bzip2.defaults do |c|
|
47
|
+
c.level = 7
|
48
|
+
end
|
38
49
|
end
|
39
|
-
compressor.best.should be_true
|
40
|
-
compressor.fast.should be_false
|
41
|
-
end
|
42
|
-
end # describe 'setting configuration defaults'
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
compressor.expects(:log!)
|
47
|
-
compressor.expects(:utility).with(:bzip2).returns('bzip2')
|
48
|
-
end
|
51
|
+
it 'should use pre-configured defaults' do
|
52
|
+
compressor.level.should == 7
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
compressor.compress_with do |cmd, ext|
|
53
|
-
cmd.should == 'bzip2 --best'
|
54
|
-
ext.should == '.bz2'
|
54
|
+
compressor.instance_variable_get(:@cmd).should == 'bzip2 -7'
|
55
|
+
compressor.instance_variable_get(:@ext).should == '.bz2'
|
55
56
|
end
|
56
|
-
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
it 'should override pre-configured defaults' do
|
59
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
60
|
+
c.level = 6
|
61
|
+
end
|
62
|
+
compressor.level.should == 6
|
63
|
+
|
64
|
+
compressor.instance_variable_get(:@cmd).should == 'bzip2 -6'
|
65
|
+
compressor.instance_variable_get(:@ext).should == '.bz2'
|
63
66
|
end
|
64
|
-
end
|
67
|
+
end # context 'when pre-configured defaults have been set'
|
68
|
+
end # describe '#initialize'
|
69
|
+
|
70
|
+
describe 'deprecations' do
|
71
|
+
describe 'fast and best options' do
|
72
|
+
context 'when only the fast option is used' do
|
73
|
+
before do
|
74
|
+
Backup::Logger.expects(:warn).with(
|
75
|
+
instance_of(Backup::Errors::ConfigurationError)
|
76
|
+
)
|
77
|
+
end
|
65
78
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
context 'when set to true' do
|
80
|
+
it 'should log a warning and set `level` to 1' do
|
81
|
+
Backup::Logger.expects(:warn).with(
|
82
|
+
"Backup::Compressor::Bzip2.level is being set to '1'"
|
83
|
+
)
|
84
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
85
|
+
c.fast = true
|
86
|
+
end
|
87
|
+
compressor.level.should be(1)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when set to false' do
|
92
|
+
it 'should only log a warning' do
|
93
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
94
|
+
c.fast = false
|
95
|
+
end
|
96
|
+
compressor.level.should be_false
|
97
|
+
end
|
98
|
+
end
|
72
99
|
end
|
73
|
-
end
|
74
100
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
101
|
+
context 'when only the best option is used' do
|
102
|
+
before do
|
103
|
+
Backup::Logger.expects(:warn).with(
|
104
|
+
instance_of(Backup::Errors::ConfigurationError)
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'when set to true' do
|
109
|
+
it 'should log a warning and set `level` to 1' do
|
110
|
+
Backup::Logger.expects(:warn).with(
|
111
|
+
"Backup::Compressor::Bzip2.level is being set to '9'"
|
112
|
+
)
|
113
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
114
|
+
c.best = true
|
115
|
+
end
|
116
|
+
compressor.level.should be(9)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when set to false' do
|
121
|
+
it 'should only log a warning' do
|
122
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
123
|
+
c.best = false
|
124
|
+
end
|
125
|
+
compressor.level.should be_false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
79
129
|
end
|
80
|
-
end
|
81
|
-
end # describe '#compress_with'
|
82
130
|
|
131
|
+
context 'when both fast and best options are used' do
|
132
|
+
before do
|
133
|
+
Backup::Logger.expects(:warn).twice.with(
|
134
|
+
instance_of(Backup::Errors::ConfigurationError)
|
135
|
+
)
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'when both are set true' do
|
139
|
+
context 'when fast is set first' do
|
140
|
+
it 'should cause the best option to be set' do
|
141
|
+
Backup::Logger.expects(:warn).with(
|
142
|
+
"Backup::Compressor::Bzip2.level is being set to '1'"
|
143
|
+
)
|
144
|
+
Backup::Logger.expects(:warn).with(
|
145
|
+
"Backup::Compressor::Bzip2.level is being set to '9'"
|
146
|
+
)
|
147
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
148
|
+
c.fast = true
|
149
|
+
c.best = true
|
150
|
+
end
|
151
|
+
compressor.level.should == 9
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when best is set first' do
|
156
|
+
it 'should cause the fast option to be set' do
|
157
|
+
Backup::Logger.expects(:warn).with(
|
158
|
+
"Backup::Compressor::Bzip2.level is being set to '1'"
|
159
|
+
)
|
160
|
+
Backup::Logger.expects(:warn).with(
|
161
|
+
"Backup::Compressor::Bzip2.level is being set to '9'"
|
162
|
+
)
|
163
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
164
|
+
c.best = true
|
165
|
+
c.fast = true
|
166
|
+
end
|
167
|
+
compressor.level.should == 1
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when only one is set true' do
|
173
|
+
context 'when fast is set true before best' do
|
174
|
+
it 'should cause the fast option to be set' do
|
175
|
+
Backup::Logger.expects(:warn).with(
|
176
|
+
"Backup::Compressor::Bzip2.level is being set to '1'"
|
177
|
+
)
|
178
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
179
|
+
c.fast = true
|
180
|
+
c.best = false
|
181
|
+
end
|
182
|
+
compressor.level.should == 1
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'when fast is set true after best' do
|
187
|
+
it 'should cause the fast option to be set' do
|
188
|
+
Backup::Logger.expects(:warn).with(
|
189
|
+
"Backup::Compressor::Bzip2.level is being set to '1'"
|
190
|
+
)
|
191
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
192
|
+
c.best = false
|
193
|
+
c.fast = true
|
194
|
+
end
|
195
|
+
compressor.level.should == 1
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'when best is set true before fast' do
|
200
|
+
it 'should cause the best option to be set' do
|
201
|
+
Backup::Logger.expects(:warn).with(
|
202
|
+
"Backup::Compressor::Bzip2.level is being set to '9'"
|
203
|
+
)
|
204
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
205
|
+
c.best = true
|
206
|
+
c.fast = false
|
207
|
+
end
|
208
|
+
compressor.level.should == 9
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'when best is set true after fast' do
|
213
|
+
it 'should cause the best option to be set' do
|
214
|
+
Backup::Logger.expects(:warn).with(
|
215
|
+
"Backup::Compressor::Bzip2.level is being set to '9'"
|
216
|
+
)
|
217
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
218
|
+
c.fast = false
|
219
|
+
c.best = true
|
220
|
+
end
|
221
|
+
compressor.level.should == 9
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'when both are set false' do
|
227
|
+
it 'should only issue the two warnings' do
|
228
|
+
compressor = Backup::Compressor::Bzip2.new do |c|
|
229
|
+
c.fast = false
|
230
|
+
c.best = false
|
231
|
+
end
|
232
|
+
compressor.level.should be_false
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end # describe 'fast and best options'
|
237
|
+
end # describe 'deprecations'
|
83
238
|
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Compressor::Custom do
|
6
|
+
let(:compressor) { Backup::Compressor::Custom.new }
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
# CLI::Helpers#utility will raise an error
|
10
|
+
# if the command is invalid or not set
|
11
|
+
Backup::Compressor::Custom.send(
|
12
|
+
:define_method, :utility,
|
13
|
+
lambda {|arg| arg.to_s.empty? ? 'error' : "/path/to/#{ arg }" }
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should be a subclass of Compressor::Base' do
|
18
|
+
Backup::Compressor::Custom.
|
19
|
+
superclass.should == Backup::Compressor::Base
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#initialize' do
|
23
|
+
let(:compressor) { Backup::Compressor::Custom.new }
|
24
|
+
|
25
|
+
after { Backup::Compressor::Custom.clear_defaults! }
|
26
|
+
|
27
|
+
it 'should load pre-configured defaults' do
|
28
|
+
Backup::Compressor::Custom.any_instance.expects(:load_defaults!)
|
29
|
+
compressor
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should call CLI::Helpers#utility to validate command' do
|
33
|
+
Backup::Compressor::Custom.any_instance.expects(:utility)
|
34
|
+
compressor
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should clean the command and extension for use with compress_with' do
|
38
|
+
compressor = Backup::Compressor::Custom.new do |c|
|
39
|
+
c.command = ' my_command --option foo '
|
40
|
+
c.extension = ' my_extension '
|
41
|
+
end
|
42
|
+
|
43
|
+
compressor.command.should == ' my_command --option foo '
|
44
|
+
compressor.extension.should == ' my_extension '
|
45
|
+
|
46
|
+
compressor.expects(:log!)
|
47
|
+
compressor.compress_with do |cmd, ext|
|
48
|
+
cmd.should == '/path/to/my_command --option foo'
|
49
|
+
ext.should == 'my_extension'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when no pre-configured defaults have been set' do
|
54
|
+
it 'should use default values' do
|
55
|
+
compressor.command.should be_nil
|
56
|
+
compressor.extension.should be_nil
|
57
|
+
|
58
|
+
compressor.instance_variable_get(:@cmd).should == 'error'
|
59
|
+
compressor.instance_variable_get(:@ext).should == ''
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should use the values given' do
|
63
|
+
compressor = Backup::Compressor::Custom.new do |c|
|
64
|
+
c.command = 'my_command'
|
65
|
+
c.extension = 'my_extension'
|
66
|
+
end
|
67
|
+
|
68
|
+
compressor.command.should == 'my_command'
|
69
|
+
compressor.extension.should == 'my_extension'
|
70
|
+
|
71
|
+
compressor.instance_variable_get(:@cmd).should == '/path/to/my_command'
|
72
|
+
compressor.instance_variable_get(:@ext).should == 'my_extension'
|
73
|
+
end
|
74
|
+
end # context 'when no pre-configured defaults have been set'
|
75
|
+
|
76
|
+
context 'when pre-configured defaults have been set' do
|
77
|
+
before do
|
78
|
+
Backup::Compressor::Custom.defaults do |c|
|
79
|
+
c.command = 'default_command'
|
80
|
+
c.extension = 'default_extension'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should use pre-configured defaults' do
|
85
|
+
compressor.command.should == 'default_command'
|
86
|
+
compressor.extension.should == 'default_extension'
|
87
|
+
|
88
|
+
compressor.instance_variable_get(:@cmd).should == '/path/to/default_command'
|
89
|
+
compressor.instance_variable_get(:@ext).should == 'default_extension'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should override pre-configured defaults' do
|
93
|
+
compressor = Backup::Compressor::Custom.new do |c|
|
94
|
+
c.command = 'new_command'
|
95
|
+
c.extension = 'new_extension'
|
96
|
+
end
|
97
|
+
|
98
|
+
compressor.command.should == 'new_command'
|
99
|
+
compressor.extension.should == 'new_extension'
|
100
|
+
|
101
|
+
compressor.instance_variable_get(:@cmd).should == '/path/to/new_command'
|
102
|
+
compressor.instance_variable_get(:@ext).should == 'new_extension'
|
103
|
+
end
|
104
|
+
end # context 'when pre-configured defaults have been set'
|
105
|
+
end # describe '#initialize'
|
106
|
+
end
|