backup-agoddard 3.0.27
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup-agoddard might be problematic. Click here for more details.
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Guardfile +23 -0
- data/LICENSE.md +24 -0
- data/README.md +478 -0
- data/backup.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +133 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +93 -0
- data/lib/backup/cli/utility.rb +255 -0
- data/lib/backup/compressor/base.rb +35 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +50 -0
- data/lib/backup/compressor/lzma.rb +52 -0
- data/lib/backup/compressor/pbzip2.rb +59 -0
- data/lib/backup/config.rb +174 -0
- data/lib/backup/configuration.rb +33 -0
- data/lib/backup/configuration/helpers.rb +130 -0
- data/lib/backup/configuration/store.rb +24 -0
- data/lib/backup/database/base.rb +53 -0
- data/lib/backup/database/mongodb.rb +230 -0
- data/lib/backup/database/mysql.rb +160 -0
- data/lib/backup/database/postgresql.rb +144 -0
- data/lib/backup/database/redis.rb +136 -0
- data/lib/backup/database/riak.rb +67 -0
- data/lib/backup/dependency.rb +108 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +760 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/hooks.rb +68 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +409 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +155 -0
- data/lib/backup/notifier/hipchat.rb +93 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/pushover.rb +88 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +100 -0
- data/lib/backup/pipeline.rb +110 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +99 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +178 -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 +46 -0
- 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 +49 -0
- data/lib/backup/syncer/rsync/local.rb +55 -0
- data/lib/backup/syncer/rsync/pull.rb +36 -0
- data/lib/backup/syncer/rsync/push.rb +116 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec-live/.gitignore +6 -0
- data/spec-live/README +7 -0
- data/spec-live/backups/config.rb +83 -0
- data/spec-live/backups/config.yml.template +46 -0
- data/spec-live/backups/models.rb +184 -0
- data/spec-live/compressor/custom_spec.rb +30 -0
- data/spec-live/compressor/gzip_spec.rb +30 -0
- data/spec-live/encryptor/gpg_keys.rb +239 -0
- data/spec-live/encryptor/gpg_spec.rb +287 -0
- data/spec-live/notifier/mail_spec.rb +121 -0
- data/spec-live/spec_helper.rb +151 -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 +335 -0
- data/spec/cleaner_spec.rb +312 -0
- data/spec/cli/helpers_spec.rb +301 -0
- data/spec/cli/utility_spec.rb +411 -0
- data/spec/compressor/base_spec.rb +52 -0
- data/spec/compressor/bzip2_spec.rb +217 -0
- data/spec/compressor/custom_spec.rb +106 -0
- data/spec/compressor/gzip_spec.rb +217 -0
- data/spec/compressor/lzma_spec.rb +123 -0
- data/spec/compressor/pbzip2_spec.rb +165 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/helpers_spec.rb +247 -0
- data/spec/configuration/store_spec.rb +39 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/database/base_spec.rb +63 -0
- data/spec/database/mongodb_spec.rb +510 -0
- data/spec/database/mysql_spec.rb +411 -0
- data/spec/database/postgresql_spec.rb +353 -0
- data/spec/database/redis_spec.rb +334 -0
- data/spec/database/riak_spec.rb +176 -0
- data/spec/dependency_spec.rb +51 -0
- data/spec/encryptor/base_spec.rb +40 -0
- data/spec/encryptor/gpg_spec.rb +909 -0
- data/spec/encryptor/open_ssl_spec.rb +148 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/hooks_spec.rb +35 -0
- data/spec/logger_spec.rb +367 -0
- data/spec/model_spec.rb +694 -0
- data/spec/notifier/base_spec.rb +104 -0
- data/spec/notifier/campfire_spec.rb +217 -0
- data/spec/notifier/hipchat_spec.rb +211 -0
- data/spec/notifier/mail_spec.rb +316 -0
- data/spec/notifier/prowl_spec.rb +138 -0
- data/spec/notifier/pushover_spec.rb +123 -0
- data/spec/notifier/twitter_spec.rb +153 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +213 -0
- data/spec/pipeline_spec.rb +259 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +166 -0
- data/spec/storage/cloudfiles_spec.rb +254 -0
- data/spec/storage/cycler_spec.rb +247 -0
- data/spec/storage/dropbox_spec.rb +480 -0
- data/spec/storage/ftp_spec.rb +271 -0
- data/spec/storage/local_spec.rb +259 -0
- data/spec/storage/ninefold_spec.rb +343 -0
- data/spec/storage/rsync_spec.rb +362 -0
- data/spec/storage/s3_spec.rb +245 -0
- data/spec/storage/scp_spec.rb +233 -0
- data/spec/storage/sftp_spec.rb +244 -0
- data/spec/syncer/base_spec.rb +109 -0
- data/spec/syncer/cloud/base_spec.rb +515 -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 +98 -0
- data/spec/syncer/rsync/local_spec.rb +149 -0
- data/spec/syncer/rsync/pull_spec.rb +98 -0
- data/spec/syncer/rsync/push_spec.rb +333 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +4 -0
- data/templates/cli/utility/compressor/custom +11 -0
- data/templates/cli/utility/compressor/gzip +4 -0
- data/templates/cli/utility/compressor/lzma +10 -0
- data/templates/cli/utility/compressor/pbzip2 +10 -0
- data/templates/cli/utility/config +32 -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 +27 -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/prowl +11 -0
- data/templates/cli/utility/notifier/pushover +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 +46 -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 +43 -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 +277 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Compressor::Lzma do
|
6
|
+
before do
|
7
|
+
Backup::Compressor::Lzma.any_instance.stubs(:utility).returns('lzma')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be a subclass of Compressor::Base' do
|
11
|
+
Backup::Compressor::Lzma.
|
12
|
+
superclass.should == Backup::Compressor::Base
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#initialize' do
|
16
|
+
let(:compressor) { Backup::Compressor::Lzma.new }
|
17
|
+
|
18
|
+
after { Backup::Compressor::Lzma.clear_defaults! }
|
19
|
+
|
20
|
+
it 'should load pre-configured defaults' do
|
21
|
+
Backup::Compressor::Lzma.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.best.should be_false
|
28
|
+
compressor.fast.should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should use the values given' do
|
32
|
+
compressor = Backup::Compressor::Lzma.new do |c|
|
33
|
+
c.best = true
|
34
|
+
c.fast = true
|
35
|
+
end
|
36
|
+
|
37
|
+
compressor.best.should be_true
|
38
|
+
compressor.fast.should be_true
|
39
|
+
end
|
40
|
+
end # context 'when no pre-configured defaults have been set'
|
41
|
+
|
42
|
+
context 'when pre-configured defaults have been set' do
|
43
|
+
before do
|
44
|
+
Backup::Compressor::Lzma.defaults do |c|
|
45
|
+
c.best = true
|
46
|
+
c.fast = true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should use pre-configured defaults' do
|
51
|
+
compressor.best.should be_true
|
52
|
+
compressor.fast.should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should override pre-configured defaults' do
|
56
|
+
compressor = Backup::Compressor::Lzma.new do |c|
|
57
|
+
c.best = false
|
58
|
+
c.fast = false
|
59
|
+
end
|
60
|
+
|
61
|
+
compressor.best.should be_false
|
62
|
+
compressor.fast.should be_false
|
63
|
+
end
|
64
|
+
end # context 'when pre-configured defaults have been set'
|
65
|
+
end # describe '#initialize'
|
66
|
+
|
67
|
+
describe '#compress_with' do
|
68
|
+
before do
|
69
|
+
Backup::Compressor::Lzma.any_instance.expects(:log!)
|
70
|
+
|
71
|
+
Backup::Logger.expects(:warn).with do |msg|
|
72
|
+
msg.should match(
|
73
|
+
/\[DEPRECATION WARNING\]\n Compressor::Lzma is being deprecated/
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should yield with the --best option' do
|
79
|
+
compressor = Backup::Compressor::Lzma.new do |c|
|
80
|
+
c.best = true
|
81
|
+
end
|
82
|
+
|
83
|
+
compressor.compress_with do |cmd, ext|
|
84
|
+
cmd.should == 'lzma --best'
|
85
|
+
ext.should == '.lzma'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should yield with the --fast option' do
|
90
|
+
compressor = Backup::Compressor::Lzma.new do |c|
|
91
|
+
c.fast = true
|
92
|
+
end
|
93
|
+
|
94
|
+
compressor.compress_with do |cmd, ext|
|
95
|
+
cmd.should == 'lzma --fast'
|
96
|
+
ext.should == '.lzma'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should prefer the --best option over --fast' do
|
101
|
+
compressor = Backup::Compressor::Lzma.new do |c|
|
102
|
+
c.best = true
|
103
|
+
c.fast = true
|
104
|
+
end
|
105
|
+
|
106
|
+
compressor.compress_with do |cmd, ext|
|
107
|
+
cmd.should == 'lzma --best'
|
108
|
+
ext.should == '.lzma'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should yield with no options' do
|
113
|
+
compressor = Backup::Compressor::Lzma.new
|
114
|
+
|
115
|
+
compressor.compress_with do |cmd, ext|
|
116
|
+
cmd.should == 'lzma'
|
117
|
+
ext.should == '.lzma'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end # describe '#compress_with'
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Compressor::Pbzip2 do
|
6
|
+
before do
|
7
|
+
Backup::Compressor::Pbzip2.any_instance.stubs(:utility).returns('pbzip2')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be a subclass of Compressor::Base' do
|
11
|
+
Backup::Compressor::Pbzip2.
|
12
|
+
superclass.should == Backup::Compressor::Base
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#initialize' do
|
16
|
+
let(:compressor) { Backup::Compressor::Pbzip2.new }
|
17
|
+
|
18
|
+
after { Backup::Compressor::Pbzip2.clear_defaults! }
|
19
|
+
|
20
|
+
it 'should load pre-configured defaults' do
|
21
|
+
Backup::Compressor::Pbzip2.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.best.should be_false
|
28
|
+
compressor.fast.should be_false
|
29
|
+
compressor.processors.should be_false
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should use the values given' do
|
33
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
34
|
+
c.best = true
|
35
|
+
c.fast = true
|
36
|
+
c.processors = 2
|
37
|
+
end
|
38
|
+
|
39
|
+
compressor.best.should be_true
|
40
|
+
compressor.fast.should be_true
|
41
|
+
compressor.processors.should == 2
|
42
|
+
end
|
43
|
+
end # context 'when no pre-configured defaults have been set'
|
44
|
+
|
45
|
+
context 'when pre-configured defaults have been set' do
|
46
|
+
before do
|
47
|
+
Backup::Compressor::Pbzip2.defaults do |c|
|
48
|
+
c.best = true
|
49
|
+
c.fast = true
|
50
|
+
c.processors = 2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should use pre-configured defaults' do
|
55
|
+
compressor.best.should be_true
|
56
|
+
compressor.fast.should be_true
|
57
|
+
compressor.processors.should == 2
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should override pre-configured defaults' do
|
61
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
62
|
+
c.best = false
|
63
|
+
c.fast = false
|
64
|
+
c.processors = 4
|
65
|
+
end
|
66
|
+
|
67
|
+
compressor.best.should be_false
|
68
|
+
compressor.fast.should be_false
|
69
|
+
compressor.processors.should == 4
|
70
|
+
end
|
71
|
+
end # context 'when pre-configured defaults have been set'
|
72
|
+
end # describe '#initialize'
|
73
|
+
|
74
|
+
describe '#compress_with' do
|
75
|
+
before do
|
76
|
+
Backup::Compressor::Pbzip2.any_instance.expects(:log!)
|
77
|
+
|
78
|
+
Backup::Logger.expects(:warn).with do |msg|
|
79
|
+
msg.should match(
|
80
|
+
/\[DEPRECATION WARNING\]\n Compressor::Pbzip2 is being deprecated/
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should yield with the --best option' do
|
86
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
87
|
+
c.best = true
|
88
|
+
end
|
89
|
+
|
90
|
+
compressor.compress_with do |cmd, ext|
|
91
|
+
cmd.should == 'pbzip2 --best'
|
92
|
+
ext.should == '.bz2'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should yield with the --fast option' do
|
97
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
98
|
+
c.fast = true
|
99
|
+
end
|
100
|
+
|
101
|
+
compressor.compress_with do |cmd, ext|
|
102
|
+
cmd.should == 'pbzip2 --fast'
|
103
|
+
ext.should == '.bz2'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should yield with the -p option' do
|
108
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
109
|
+
c.processors = 2
|
110
|
+
end
|
111
|
+
|
112
|
+
compressor.compress_with do |cmd, ext|
|
113
|
+
cmd.should == 'pbzip2 -p2'
|
114
|
+
ext.should == '.bz2'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should prefer the --best option over --fast' do
|
119
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
120
|
+
c.best = true
|
121
|
+
c.fast = true
|
122
|
+
end
|
123
|
+
|
124
|
+
compressor.compress_with do |cmd, ext|
|
125
|
+
cmd.should == 'pbzip2 --best'
|
126
|
+
ext.should == '.bz2'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should yield with the --best and -p options' do
|
131
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
132
|
+
c.best = true
|
133
|
+
c.processors = 2
|
134
|
+
end
|
135
|
+
|
136
|
+
compressor.compress_with do |cmd, ext|
|
137
|
+
cmd.should == 'pbzip2 --best -p2'
|
138
|
+
ext.should == '.bz2'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should yield with the --fast and -p options' do
|
143
|
+
compressor = Backup::Compressor::Pbzip2.new do |c|
|
144
|
+
c.fast = true
|
145
|
+
c.processors = 2
|
146
|
+
end
|
147
|
+
|
148
|
+
compressor.compress_with do |cmd, ext|
|
149
|
+
cmd.should == 'pbzip2 --fast -p2'
|
150
|
+
ext.should == '.bz2'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should yield with no options' do
|
155
|
+
compressor = Backup::Compressor::Pbzip2.new
|
156
|
+
|
157
|
+
compressor.compress_with do |cmd, ext|
|
158
|
+
cmd.should == 'pbzip2'
|
159
|
+
ext.should == '.bz2'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end # describe '#compress_with'
|
164
|
+
|
165
|
+
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
|