backup 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -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 +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -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 +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -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_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -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 +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
@@ -5,54 +5,79 @@ require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
5
5
|
describe Backup::Compressor::Gzip do
|
6
6
|
let(:compressor) { Backup::Compressor::Gzip.new }
|
7
7
|
|
8
|
-
|
9
|
-
Backup::
|
10
|
-
end
|
8
|
+
describe 'setting configuration defaults' do
|
9
|
+
after { Backup::Configuration::Compressor::Gzip.clear_defaults! }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
25
|
|
17
|
-
|
18
|
-
compressor.
|
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
|
19
41
|
end
|
20
|
-
end
|
42
|
+
end # describe 'setting configuration defaults'
|
21
43
|
|
22
|
-
describe '#
|
44
|
+
describe '#compress_with' do
|
23
45
|
before do
|
24
|
-
|
46
|
+
compressor.expects(:log!)
|
47
|
+
compressor.expects(:utility).with(:gzip).returns('gzip')
|
25
48
|
end
|
26
49
|
|
27
|
-
it 'should
|
28
|
-
compressor.
|
29
|
-
compressor.
|
30
|
-
|
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
|
31
56
|
end
|
32
57
|
|
33
|
-
it 'should
|
34
|
-
compressor =
|
35
|
-
|
36
|
-
|
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'
|
37
63
|
end
|
38
|
-
|
39
|
-
compressor.stubs(:utility).returns(:gzip)
|
40
|
-
compressor.expects(:run).with("gzip --best --fast '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'")
|
41
|
-
compressor.perform!
|
42
64
|
end
|
43
65
|
|
44
|
-
it 'should
|
45
|
-
compressor.
|
46
|
-
compressor.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
51
73
|
end
|
52
74
|
|
53
|
-
it 'should
|
54
|
-
|
55
|
-
|
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
|
56
80
|
end
|
57
|
-
end
|
81
|
+
end # describe '#compress_with'
|
82
|
+
|
58
83
|
end
|
@@ -5,54 +5,79 @@ require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
5
5
|
describe Backup::Compressor::Lzma do
|
6
6
|
let(:compressor) { Backup::Compressor::Lzma.new }
|
7
7
|
|
8
|
-
|
9
|
-
Backup::
|
10
|
-
end
|
8
|
+
describe 'setting configuration defaults' do
|
9
|
+
after { Backup::Configuration::Compressor::Lzma.clear_defaults! }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
25
|
|
17
|
-
|
18
|
-
compressor.
|
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
|
19
41
|
end
|
20
|
-
end
|
42
|
+
end # describe 'setting configuration defaults'
|
21
43
|
|
22
|
-
describe '#
|
44
|
+
describe '#compress_with' do
|
23
45
|
before do
|
24
|
-
|
46
|
+
compressor.expects(:log!)
|
47
|
+
compressor.expects(:utility).with(:lzma).returns('lzma')
|
25
48
|
end
|
26
49
|
|
27
|
-
it 'should
|
28
|
-
compressor.
|
29
|
-
compressor.
|
30
|
-
|
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
|
31
56
|
end
|
32
57
|
|
33
|
-
it 'should
|
34
|
-
compressor =
|
35
|
-
|
36
|
-
|
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'
|
37
63
|
end
|
38
|
-
|
39
|
-
compressor.stubs(:utility).returns(:lzma)
|
40
|
-
compressor.expects(:run).with("lzma --best --fast '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'")
|
41
|
-
compressor.perform!
|
42
64
|
end
|
43
65
|
|
44
|
-
it 'should
|
45
|
-
compressor.
|
46
|
-
compressor.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
51
73
|
end
|
52
74
|
|
53
|
-
it 'should
|
54
|
-
|
55
|
-
|
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
|
56
80
|
end
|
57
|
-
end
|
81
|
+
end # describe '#compress_with'
|
82
|
+
|
58
83
|
end
|
@@ -5,59 +5,120 @@ require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
5
5
|
describe Backup::Compressor::Pbzip2 do
|
6
6
|
let(:compressor) { Backup::Compressor::Pbzip2.new }
|
7
7
|
|
8
|
-
|
9
|
-
Backup::
|
10
|
-
end
|
8
|
+
describe 'setting configuration defaults' do
|
9
|
+
after { Backup::Configuration::Compressor::Pbzip2.clear_defaults! }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
15
|
|
17
|
-
|
18
|
-
compressor.
|
19
|
-
|
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
|
20
29
|
|
21
|
-
|
22
|
-
compressor.
|
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
|
23
55
|
end
|
24
|
-
end
|
56
|
+
end # describe 'setting configuration defaults'
|
25
57
|
|
26
|
-
describe '#
|
58
|
+
describe '#compress_with' do
|
27
59
|
before do
|
28
|
-
|
60
|
+
compressor.expects(:log!)
|
61
|
+
compressor.expects(:utility).with(:pbzip2).returns('pbzip2')
|
29
62
|
end
|
30
63
|
|
31
|
-
it 'should
|
32
|
-
compressor.
|
33
|
-
compressor.
|
34
|
-
|
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
|
35
70
|
end
|
36
71
|
|
37
|
-
it 'should
|
38
|
-
compressor =
|
39
|
-
|
40
|
-
|
41
|
-
|
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'
|
42
77
|
end
|
78
|
+
end
|
43
79
|
|
44
|
-
|
45
|
-
compressor.
|
46
|
-
compressor.
|
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
|
47
86
|
end
|
48
87
|
|
49
|
-
it 'should
|
50
|
-
compressor.
|
51
|
-
compressor.
|
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
|
52
96
|
|
53
|
-
|
54
|
-
compressor.
|
55
|
-
|
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
|
56
104
|
end
|
57
105
|
|
58
|
-
it 'should
|
59
|
-
|
60
|
-
compressor.
|
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
|
61
113
|
end
|
62
|
-
|
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
|
+
|
63
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
|