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
@@ -20,49 +20,66 @@ describe Backup::Database::PostgreSQL do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
it 'should be a subclass of Database::Base' do
|
24
|
+
Backup::Database::PostgreSQL.superclass.
|
25
|
+
should == Backup::Database::Base
|
26
|
+
end
|
27
|
+
|
23
28
|
describe '#initialize' do
|
24
|
-
it 'should read the adapter details correctly' do
|
25
|
-
db.name.should == 'mydatabase'
|
26
|
-
db.username.should == 'someuser'
|
27
|
-
db.password.should == 'secret'
|
28
|
-
db.host.should == 'localhost'
|
29
|
-
db.port.should == '123'
|
30
|
-
db.socket.should == '/pgsql.sock'
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
db
|
35
|
-
db.pg_dump_utility.should == '/path/to/pg_dump'
|
30
|
+
it 'should load pre-configured defaults through Base' do
|
31
|
+
Backup::Database::PostgreSQL.any_instance.expects(:load_defaults!)
|
32
|
+
db
|
36
33
|
end
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
it 'should pass the model reference to Base' do
|
36
|
+
db.instance_variable_get(:@model).should == model
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when no pre-configured defaults have been set' do
|
40
|
+
context 'when options are specified' do
|
41
|
+
it 'should use the given values' do
|
42
|
+
db.name.should == 'mydatabase'
|
43
|
+
db.username.should == 'someuser'
|
44
|
+
db.password.should == 'secret'
|
45
|
+
db.host.should == 'localhost'
|
46
|
+
db.port.should == '123'
|
47
|
+
db.socket.should == '/pgsql.sock'
|
48
|
+
|
49
|
+
db.skip_tables.should == ['logs', 'profiles']
|
50
|
+
db.only_tables.should == ['users', 'pirates']
|
51
|
+
db.additional_options.should == ['--single-transaction', '--quick']
|
52
|
+
db.pg_dump_utility.should == '/path/to/pg_dump'
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
|
-
|
45
|
-
|
56
|
+
context 'when options are not specified' do
|
57
|
+
before do
|
58
|
+
Backup::Database::PostgreSQL.any_instance.expects(:utility).
|
59
|
+
with(:pg_dump).returns('/real/pg_dump')
|
60
|
+
end
|
46
61
|
|
47
|
-
|
48
|
-
|
49
|
-
db.password.should be_nil
|
50
|
-
db.host.should be_nil
|
51
|
-
db.port.should be_nil
|
52
|
-
db.socket.should be_nil
|
62
|
+
it 'should provide default values' do
|
63
|
+
db = Backup::Database::PostgreSQL.new(model)
|
53
64
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
65
|
+
db.name.should be_nil
|
66
|
+
db.username.should be_nil
|
67
|
+
db.password.should be_nil
|
68
|
+
db.host.should be_nil
|
69
|
+
db.port.should be_nil
|
70
|
+
db.socket.should be_nil
|
60
71
|
|
61
|
-
|
62
|
-
|
72
|
+
db.skip_tables.should == []
|
73
|
+
db.only_tables.should == []
|
74
|
+
db.additional_options.should == []
|
75
|
+
db.pg_dump_utility.should == '/real/pg_dump'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end # context 'when no pre-configured defaults have been set'
|
63
79
|
|
64
|
-
|
65
|
-
|
80
|
+
context 'when pre-configured defaults have been set' do
|
81
|
+
before do
|
82
|
+
Backup::Database::PostgreSQL.defaults do |db|
|
66
83
|
db.name = 'db_name'
|
67
84
|
db.username = 'db_username'
|
68
85
|
db.password = 'db_password'
|
@@ -73,27 +90,52 @@ describe Backup::Database::PostgreSQL do
|
|
73
90
|
db.skip_tables = ['skip', 'tables']
|
74
91
|
db.only_tables = ['only', 'tables']
|
75
92
|
db.additional_options = ['--add', '--opts']
|
76
|
-
db.pg_dump_utility
|
93
|
+
db.pg_dump_utility = '/default/path/to/pg_dump'
|
77
94
|
end
|
95
|
+
end
|
78
96
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
97
|
+
after { Backup::Database::PostgreSQL.clear_defaults! }
|
98
|
+
|
99
|
+
context 'when options are specified' do
|
100
|
+
it 'should override the pre-configured defaults' do
|
101
|
+
db.name.should == 'mydatabase'
|
102
|
+
db.username.should == 'someuser'
|
103
|
+
db.password.should == 'secret'
|
104
|
+
db.host.should == 'localhost'
|
105
|
+
db.port.should == '123'
|
106
|
+
db.socket.should == '/pgsql.sock'
|
107
|
+
|
108
|
+
db.skip_tables.should == ['logs', 'profiles']
|
109
|
+
db.only_tables.should == ['users', 'pirates']
|
110
|
+
db.additional_options.should == ['--single-transaction', '--quick']
|
111
|
+
db.pg_dump_utility.should == '/path/to/pg_dump'
|
112
|
+
end
|
113
|
+
end
|
86
114
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
115
|
+
context 'when options are not specified' do
|
116
|
+
it 'should use the pre-configured defaults' do
|
117
|
+
db = Backup::Database::PostgreSQL.new(model)
|
118
|
+
|
119
|
+
db.name.should == 'db_name'
|
120
|
+
db.username.should == 'db_username'
|
121
|
+
db.password.should == 'db_password'
|
122
|
+
db.host.should == 'db_host'
|
123
|
+
db.port.should == 789
|
124
|
+
db.socket.should == '/foo.sock'
|
125
|
+
|
126
|
+
db.skip_tables.should == ['skip', 'tables']
|
127
|
+
db.only_tables.should == ['only', 'tables']
|
128
|
+
db.additional_options.should == ['--add', '--opts']
|
129
|
+
db.pg_dump_utility.should == '/default/path/to/pg_dump'
|
130
|
+
end
|
91
131
|
end
|
92
|
-
end
|
132
|
+
end # context 'when no pre-configured defaults have been set'
|
93
133
|
end # describe '#initialize'
|
94
134
|
|
95
135
|
describe '#perform!' do
|
96
136
|
let(:s) { sequence '' }
|
137
|
+
let(:pipeline) { mock }
|
138
|
+
|
97
139
|
before do
|
98
140
|
# superclass actions
|
99
141
|
db.expects(:prepare!).in_sequence(s)
|
@@ -101,17 +143,25 @@ describe Backup::Database::PostgreSQL do
|
|
101
143
|
db.instance_variable_set(:@dump_path, '/dump/path')
|
102
144
|
|
103
145
|
db.stubs(:pgdump).returns('pgdump_command')
|
146
|
+
Backup::Pipeline.expects(:new).returns(pipeline)
|
104
147
|
end
|
105
148
|
|
106
149
|
context 'when no compressor is configured' do
|
107
150
|
before do
|
108
|
-
model.expects(:compressor).
|
151
|
+
model.expects(:compressor).returns(nil)
|
109
152
|
end
|
110
153
|
|
111
154
|
it 'should run pgdump without compression' do
|
112
|
-
|
113
|
-
|
155
|
+
pipeline.expects(:<<).in_sequence(s).with('pgdump_command')
|
156
|
+
pipeline.expects(:<<).in_sequence(s).with(
|
157
|
+
"cat > '/dump/path/mydatabase.sql'"
|
158
|
+
)
|
159
|
+
pipeline.expects(:run).in_sequence(s)
|
160
|
+
pipeline.expects(:success?).in_sequence(s).returns(true)
|
161
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
162
|
+
'Database::PostgreSQL Complete!'
|
114
163
|
)
|
164
|
+
|
115
165
|
db.perform!
|
116
166
|
end
|
117
167
|
end
|
@@ -119,18 +169,46 @@ describe Backup::Database::PostgreSQL do
|
|
119
169
|
context 'when a compressor is configured' do
|
120
170
|
before do
|
121
171
|
compressor = mock
|
122
|
-
model.expects(:compressor).twice.
|
123
|
-
compressor.expects(:compress_with).
|
172
|
+
model.expects(:compressor).twice.returns(compressor)
|
173
|
+
compressor.expects(:compress_with).yields('gzip', '.gz')
|
124
174
|
end
|
125
175
|
|
126
176
|
it 'should run pgdump with compression' do
|
127
|
-
|
128
|
-
|
177
|
+
pipeline.expects(:<<).in_sequence(s).with('pgdump_command')
|
178
|
+
pipeline.expects(:<<).in_sequence(s).with('gzip')
|
179
|
+
pipeline.expects(:<<).in_sequence(s).with(
|
180
|
+
"cat > '/dump/path/mydatabase.sql.gz'"
|
181
|
+
)
|
182
|
+
pipeline.expects(:run).in_sequence(s)
|
183
|
+
pipeline.expects(:success?).in_sequence(s).returns(true)
|
184
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
185
|
+
'Database::PostgreSQL Complete!'
|
129
186
|
)
|
187
|
+
|
130
188
|
db.perform!
|
131
189
|
end
|
132
190
|
end
|
133
191
|
|
192
|
+
context 'when pipeline command fails' do
|
193
|
+
before do
|
194
|
+
model.expects(:compressor).returns(nil)
|
195
|
+
pipeline.stubs(:<<)
|
196
|
+
pipeline.expects(:run)
|
197
|
+
pipeline.expects(:success?).returns(false)
|
198
|
+
pipeline.expects(:error_messages).returns('pipeline_errors')
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should raise an error' do
|
202
|
+
expect do
|
203
|
+
db.perform!
|
204
|
+
end.to raise_error(
|
205
|
+
Backup::Errors::Database::PipelineError,
|
206
|
+
"Database::PipelineError: Database::PostgreSQL Dump Failed!\n" +
|
207
|
+
" pipeline_errors"
|
208
|
+
)
|
209
|
+
end
|
210
|
+
end # context 'when pipeline command fails'
|
211
|
+
|
134
212
|
end # describe '#perform!'
|
135
213
|
|
136
214
|
describe '#pgdump' do
|
@@ -237,4 +315,40 @@ describe Backup::Database::PostgreSQL do
|
|
237
315
|
end
|
238
316
|
end
|
239
317
|
|
318
|
+
describe 'deprecations' do
|
319
|
+
after do
|
320
|
+
Backup::Database::PostgreSQL.clear_defaults!
|
321
|
+
end
|
322
|
+
|
323
|
+
describe '#utility_path' do
|
324
|
+
before do
|
325
|
+
Backup::Database::PostgreSQL.any_instance.stubs(:utility)
|
326
|
+
Backup::Logger.expects(:warn).with(
|
327
|
+
instance_of(Backup::Errors::ConfigurationError)
|
328
|
+
)
|
329
|
+
Backup::Logger.expects(:warn).with(
|
330
|
+
"Backup::Database::PostgreSQL.pg_dump_utility is being set to 'foo'"
|
331
|
+
)
|
332
|
+
end
|
333
|
+
|
334
|
+
context 'when set directly' do
|
335
|
+
it 'should issue a deprecation warning and set the replacement value' do
|
336
|
+
postgresql = Backup::Database::PostgreSQL.new(model) do |db|
|
337
|
+
db.utility_path = 'foo'
|
338
|
+
end
|
339
|
+
postgresql.pg_dump_utility.should == 'foo'
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
context 'when set as a default' do
|
344
|
+
it 'should issue a deprecation warning and set the replacement value' do
|
345
|
+
postgresql = Backup::Database::PostgreSQL.defaults do |db|
|
346
|
+
db.utility_path = 'foo'
|
347
|
+
end
|
348
|
+
postgresql = Backup::Database::PostgreSQL.new(model)
|
349
|
+
postgresql.pg_dump_utility.should == 'foo'
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end # describe '#utility_path'
|
353
|
+
end
|
240
354
|
end
|
data/spec/database/redis_spec.rb
CHANGED
@@ -19,47 +19,64 @@ describe Backup::Database::Redis do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
it 'should be a subclass of Database::Base' do
|
23
|
+
Backup::Database::Redis.superclass.
|
24
|
+
should == Backup::Database::Base
|
25
|
+
end
|
26
|
+
|
22
27
|
describe '#initialize' do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
db
|
27
|
-
db.host.should == 'localhost'
|
28
|
-
db.port.should == '123'
|
29
|
-
db.socket.should == '/redis.sock'
|
30
|
-
db.invoke_save.should == true
|
31
|
-
|
32
|
-
db.additional_options.should == ['--query', '--foo']
|
33
|
-
db.redis_cli_utility.should == '/path/to/redis-cli'
|
28
|
+
|
29
|
+
it 'should load pre-configured defaults through Base' do
|
30
|
+
Backup::Database::Redis.any_instance.expects(:load_defaults!)
|
31
|
+
db
|
34
32
|
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
it 'should pass the model reference to Base' do
|
35
|
+
db.instance_variable_get(:@model).should == model
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when no pre-configured defaults have been set' do
|
39
|
+
context 'when options are specified' do
|
40
|
+
it 'should use the given values' do
|
41
|
+
db.name.should == 'mydatabase'
|
42
|
+
db.path.should == '/var/lib/redis/db/'
|
43
|
+
db.password.should == 'secret'
|
44
|
+
db.host.should == 'localhost'
|
45
|
+
db.port.should == '123'
|
46
|
+
db.socket.should == '/redis.sock'
|
47
|
+
db.invoke_save.should == true
|
48
|
+
|
49
|
+
db.additional_options.should == ['--query', '--foo']
|
50
|
+
db.redis_cli_utility.should == '/path/to/redis-cli'
|
51
|
+
end
|
40
52
|
end
|
41
53
|
|
42
|
-
|
43
|
-
|
54
|
+
context 'when options are not specified' do
|
55
|
+
before do
|
56
|
+
Backup::Database::Redis.any_instance.expects(:utility).
|
57
|
+
with('redis-cli').returns('/real/redis-cli')
|
58
|
+
end
|
44
59
|
|
45
|
-
|
46
|
-
|
47
|
-
db.password.should be_nil
|
48
|
-
db.host.should be_nil
|
49
|
-
db.port.should be_nil
|
50
|
-
db.socket.should be_nil
|
51
|
-
db.invoke_save.should be_nil
|
60
|
+
it 'should provide default values' do
|
61
|
+
db = Backup::Database::Redis.new(model)
|
52
62
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
63
|
+
db.name.should == 'dump'
|
64
|
+
db.path.should be_nil
|
65
|
+
db.password.should be_nil
|
66
|
+
db.host.should be_nil
|
67
|
+
db.port.should be_nil
|
68
|
+
db.socket.should be_nil
|
69
|
+
db.invoke_save.should be_nil
|
57
70
|
|
58
|
-
|
59
|
-
|
71
|
+
db.additional_options.should == []
|
72
|
+
db.redis_cli_utility.should == '/real/redis-cli'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end # context 'when no pre-configured defaults have been set'
|
60
76
|
|
61
|
-
|
62
|
-
|
77
|
+
context 'when pre-configured defaults have been set' do
|
78
|
+
before do
|
79
|
+
Backup::Database::Redis.defaults do |db|
|
63
80
|
db.name = 'db_name'
|
64
81
|
db.path = 'db_path'
|
65
82
|
db.password = 'db_password'
|
@@ -71,20 +88,42 @@ describe Backup::Database::Redis do
|
|
71
88
|
db.additional_options = ['--add', '--opts']
|
72
89
|
db.redis_cli_utility = '/default/path/to/redis-cli'
|
73
90
|
end
|
91
|
+
end
|
74
92
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
93
|
+
after { Backup::Database::Redis.clear_defaults! }
|
94
|
+
|
95
|
+
context 'when options are specified' do
|
96
|
+
it 'should override the pre-configured defaults' do
|
97
|
+
db.name.should == 'mydatabase'
|
98
|
+
db.path.should == '/var/lib/redis/db/'
|
99
|
+
db.password.should == 'secret'
|
100
|
+
db.host.should == 'localhost'
|
101
|
+
db.port.should == '123'
|
102
|
+
db.socket.should == '/redis.sock'
|
103
|
+
db.invoke_save.should == true
|
104
|
+
|
105
|
+
db.additional_options.should == ['--query', '--foo']
|
106
|
+
db.redis_cli_utility.should == '/path/to/redis-cli'
|
107
|
+
end
|
86
108
|
end
|
87
|
-
|
109
|
+
|
110
|
+
context 'when options are not specified' do
|
111
|
+
it 'should use the pre-configured defaults' do
|
112
|
+
db = Backup::Database::Redis.new(model)
|
113
|
+
|
114
|
+
db.name.should == 'db_name'
|
115
|
+
db.path.should == 'db_path'
|
116
|
+
db.password.should == 'db_password'
|
117
|
+
db.host.should == 'db_host'
|
118
|
+
db.port.should == 789
|
119
|
+
db.socket.should == '/foo.sock'
|
120
|
+
db.invoke_save.should == true
|
121
|
+
|
122
|
+
db.additional_options.should == ['--add', '--opts']
|
123
|
+
db.redis_cli_utility.should == '/default/path/to/redis-cli'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end # context 'when no pre-configured defaults have been set'
|
88
127
|
end # describe '#initialize'
|
89
128
|
|
90
129
|
describe '#perform!' do
|
@@ -197,11 +236,11 @@ describe Backup::Database::Redis do
|
|
197
236
|
File.expects(:exist?).returns(false)
|
198
237
|
expect do
|
199
238
|
db.send(:copy!)
|
200
|
-
end.to raise_error
|
239
|
+
end.to raise_error {|err|
|
201
240
|
err.should be_an_instance_of Backup::Errors::Database::Redis::NotFoundError
|
202
241
|
err.message.should match(/Redis database dump not found/)
|
203
242
|
err.message.should match(/File path was #{src_path}/)
|
204
|
-
|
243
|
+
}
|
205
244
|
end
|
206
245
|
end
|
207
246
|
end # describe '#copy!'
|
@@ -257,4 +296,40 @@ describe Backup::Database::Redis do
|
|
257
296
|
end
|
258
297
|
end
|
259
298
|
|
299
|
+
describe 'deprecations' do
|
300
|
+
after do
|
301
|
+
Backup::Database::Redis.clear_defaults!
|
302
|
+
end
|
303
|
+
|
304
|
+
describe '#utility_path' do
|
305
|
+
before do
|
306
|
+
Backup::Database::Redis.any_instance.stubs(:utility)
|
307
|
+
Backup::Logger.expects(:warn).with(
|
308
|
+
instance_of(Backup::Errors::ConfigurationError)
|
309
|
+
)
|
310
|
+
Backup::Logger.expects(:warn).with(
|
311
|
+
"Backup::Database::Redis.redis_cli_utility is being set to 'foo'"
|
312
|
+
)
|
313
|
+
end
|
314
|
+
|
315
|
+
context 'when set directly' do
|
316
|
+
it 'should issue a deprecation warning and set the replacement value' do
|
317
|
+
redis = Backup::Database::Redis.new(model) do |db|
|
318
|
+
db.utility_path = 'foo'
|
319
|
+
end
|
320
|
+
redis.redis_cli_utility.should == 'foo'
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
context 'when set as a default' do
|
325
|
+
it 'should issue a deprecation warning and set the replacement value' do
|
326
|
+
redis = Backup::Database::Redis.defaults do |db|
|
327
|
+
db.utility_path = 'foo'
|
328
|
+
end
|
329
|
+
redis = Backup::Database::Redis.new(model)
|
330
|
+
redis.redis_cli_utility.should == 'foo'
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end # describe '#utility_path'
|
334
|
+
end
|
260
335
|
end
|