backup-agoddard 3.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,480 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
4
|
+
|
|
5
|
+
describe Backup::Storage::Dropbox do
|
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
|
7
|
+
let(:storage) do
|
|
8
|
+
Backup::Storage::Dropbox.new(model) do |db|
|
|
9
|
+
db.api_key = 'my_api_key'
|
|
10
|
+
db.api_secret = 'my_api_secret'
|
|
11
|
+
db.keep = 5
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'should be a subclass of Storage::Base' do
|
|
16
|
+
Backup::Storage::Dropbox.
|
|
17
|
+
superclass.should == Backup::Storage::Base
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe '#initialize' do
|
|
21
|
+
after { Backup::Storage::Dropbox.clear_defaults! }
|
|
22
|
+
|
|
23
|
+
it 'should load pre-configured defaults through Base' do
|
|
24
|
+
Backup::Storage::Dropbox.any_instance.expects(:load_defaults!)
|
|
25
|
+
storage
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should pass the model reference to Base' do
|
|
29
|
+
storage.instance_variable_get(:@model).should == model
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should pass the storage_id to Base' do
|
|
33
|
+
storage = Backup::Storage::Dropbox.new(model, 'my_storage_id')
|
|
34
|
+
storage.storage_id.should == 'my_storage_id'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'when no pre-configured defaults have been set' do
|
|
38
|
+
it 'should use the values given' do
|
|
39
|
+
storage.api_key.should == 'my_api_key'
|
|
40
|
+
storage.api_secret.should == 'my_api_secret'
|
|
41
|
+
storage.access_type.should == :app_folder
|
|
42
|
+
storage.path.should == 'backups'
|
|
43
|
+
|
|
44
|
+
storage.storage_id.should be_nil
|
|
45
|
+
storage.keep.should == 5
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'should use default values if none are given' do
|
|
49
|
+
storage = Backup::Storage::Dropbox.new(model)
|
|
50
|
+
storage.api_key.should be_nil
|
|
51
|
+
storage.api_secret.should be_nil
|
|
52
|
+
storage.access_type.should == :app_folder
|
|
53
|
+
storage.path.should == 'backups'
|
|
54
|
+
|
|
55
|
+
storage.storage_id.should be_nil
|
|
56
|
+
storage.keep.should be_nil
|
|
57
|
+
end
|
|
58
|
+
end # context 'when no pre-configured defaults have been set'
|
|
59
|
+
|
|
60
|
+
context 'when pre-configured defaults have been set' do
|
|
61
|
+
before do
|
|
62
|
+
Backup::Storage::Dropbox.defaults do |s|
|
|
63
|
+
s.api_key = 'some_api_key'
|
|
64
|
+
s.api_secret = 'some_api_secret'
|
|
65
|
+
s.access_type = 'some_access_type'
|
|
66
|
+
s.path = 'some_path'
|
|
67
|
+
s.keep = 15
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'should use pre-configured defaults' do
|
|
72
|
+
storage = Backup::Storage::Dropbox.new(model)
|
|
73
|
+
|
|
74
|
+
storage.api_key.should == 'some_api_key'
|
|
75
|
+
storage.api_secret.should == 'some_api_secret'
|
|
76
|
+
storage.access_type.should == 'some_access_type'
|
|
77
|
+
storage.path.should == 'some_path'
|
|
78
|
+
|
|
79
|
+
storage.storage_id.should be_nil
|
|
80
|
+
storage.keep.should == 15
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'should override pre-configured defaults' do
|
|
84
|
+
storage = Backup::Storage::Dropbox.new(model) do |s|
|
|
85
|
+
s.api_key = 'new_api_key'
|
|
86
|
+
s.api_secret = 'new_api_secret'
|
|
87
|
+
s.access_type = 'new_access_type'
|
|
88
|
+
s.path = 'new_path'
|
|
89
|
+
s.keep = 10
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
storage.api_key.should == 'new_api_key'
|
|
93
|
+
storage.api_secret.should == 'new_api_secret'
|
|
94
|
+
storage.access_type.should == 'new_access_type'
|
|
95
|
+
storage.path.should == 'new_path'
|
|
96
|
+
|
|
97
|
+
storage.storage_id.should be_nil
|
|
98
|
+
storage.keep.should == 10
|
|
99
|
+
end
|
|
100
|
+
end # context 'when pre-configured defaults have been set'
|
|
101
|
+
end # describe '#initialize'
|
|
102
|
+
|
|
103
|
+
describe '#connection' do
|
|
104
|
+
let(:session) { mock }
|
|
105
|
+
let(:client) { mock }
|
|
106
|
+
let(:s) { sequence '' }
|
|
107
|
+
|
|
108
|
+
context 'when a cached session exists' do
|
|
109
|
+
before do
|
|
110
|
+
storage.expects(:cached_session).in_sequence(s).returns(session)
|
|
111
|
+
storage.expects(:create_write_and_return_new_session!).never
|
|
112
|
+
DropboxClient.expects(:new).in_sequence(s).
|
|
113
|
+
with(session, :app_folder).returns(client)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'should use the cached session to create the client' do
|
|
117
|
+
storage.send(:connection).should be(client)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'should return an already existing client' do
|
|
121
|
+
storage.send(:connection).should be(client)
|
|
122
|
+
storage.send(:connection).should be(client)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context 'when a cached session does not exist' do
|
|
127
|
+
before do
|
|
128
|
+
storage.expects(:cached_session).in_sequence(s).returns(false)
|
|
129
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
130
|
+
'Creating a new session!'
|
|
131
|
+
)
|
|
132
|
+
storage.expects(:create_write_and_return_new_session!).in_sequence(s).
|
|
133
|
+
returns(session)
|
|
134
|
+
DropboxClient.expects(:new).in_sequence(s).
|
|
135
|
+
with(session, :app_folder).returns(client)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'should create a new session and return the client' do
|
|
139
|
+
storage.send(:connection).should be(client)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'should return an already existing client' do
|
|
143
|
+
storage.send(:connection).should be(client)
|
|
144
|
+
storage.send(:connection).should be(client)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
context 'when an error is raised creating a client for the session' do
|
|
149
|
+
it 'should wrap and raise the error' do
|
|
150
|
+
storage.stubs(:cached_session).returns(true)
|
|
151
|
+
DropboxClient.expects(:new).raises('error')
|
|
152
|
+
|
|
153
|
+
expect do
|
|
154
|
+
storage.send(:connection)
|
|
155
|
+
end.to raise_error {|err|
|
|
156
|
+
err.should be_an_instance_of(
|
|
157
|
+
Backup::Errors::Storage::Dropbox::ConnectionError
|
|
158
|
+
)
|
|
159
|
+
err.message.should ==
|
|
160
|
+
'Storage::Dropbox::ConnectionError: RuntimeError: error'
|
|
161
|
+
}
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
end # describe '#connection'
|
|
166
|
+
|
|
167
|
+
describe '#cached_session' do
|
|
168
|
+
let(:session) { mock }
|
|
169
|
+
|
|
170
|
+
context 'when a cached session file exists' do
|
|
171
|
+
before do
|
|
172
|
+
storage.expects(:cache_exists?).returns(true)
|
|
173
|
+
storage.expects(:cached_file).returns('cached_file')
|
|
174
|
+
File.expects(:read).with('cached_file').returns('yaml_data')
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
context 'when the cached session is successfully loaded' do
|
|
178
|
+
it 'should return the sesssion' do
|
|
179
|
+
DropboxSession.expects(:deserialize).with('yaml_data').
|
|
180
|
+
returns(session)
|
|
181
|
+
Backup::Logger.expects(:message).with(
|
|
182
|
+
'Session data loaded from cache!'
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
storage.send(:cached_session).should be(session)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
context 'when errors occur loading the session' do
|
|
190
|
+
it 'should log a warning and return false' do
|
|
191
|
+
DropboxSession.expects(:deserialize).with('yaml_data').
|
|
192
|
+
raises('error message')
|
|
193
|
+
Backup::Logger.expects(:warn).with do |err|
|
|
194
|
+
err.should be_an_instance_of(
|
|
195
|
+
Backup::Errors::Storage::Dropbox::CacheError
|
|
196
|
+
)
|
|
197
|
+
err.message.should == 'Storage::Dropbox::CacheError: ' +
|
|
198
|
+
"Could not read session data from cache.\n" +
|
|
199
|
+
" Cache data might be corrupt.\n" +
|
|
200
|
+
" Reason: RuntimeError\n" +
|
|
201
|
+
" error message"
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
expect do
|
|
205
|
+
storage.send(:cached_session).should be_false
|
|
206
|
+
end.not_to raise_error
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
context 'when a cached session file does not exist' do
|
|
212
|
+
before { storage.stubs(:cache_exists?).returns(false) }
|
|
213
|
+
it 'should return false' do
|
|
214
|
+
storage.send(:cached_session).should be_false
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
describe '#transfer!' do
|
|
220
|
+
let(:connection) { mock }
|
|
221
|
+
let(:package) { mock }
|
|
222
|
+
let(:file) { mock }
|
|
223
|
+
let(:s) { sequence '' }
|
|
224
|
+
|
|
225
|
+
before do
|
|
226
|
+
storage.instance_variable_set(:@package, package)
|
|
227
|
+
storage.stubs(:storage_name).returns('Storage::Dropbox')
|
|
228
|
+
storage.stubs(:local_path).returns('/local/path')
|
|
229
|
+
storage.stubs(:connection).returns(connection)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it 'should transfer the package files' do
|
|
233
|
+
storage.expects(:remote_path_for).in_sequence(s).with(package).
|
|
234
|
+
returns('remote/path')
|
|
235
|
+
storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
|
|
236
|
+
multiple_yields(
|
|
237
|
+
['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
|
|
238
|
+
['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
|
|
239
|
+
)
|
|
240
|
+
# first yield
|
|
241
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
242
|
+
"Storage::Dropbox started transferring " +
|
|
243
|
+
"'2011.12.31.11.00.02.backup.tar.enc-aa'."
|
|
244
|
+
)
|
|
245
|
+
File.expects(:open).in_sequence(s).with(
|
|
246
|
+
File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'), 'r'
|
|
247
|
+
).yields(file)
|
|
248
|
+
connection.expects(:put_file).in_sequence(s).with(
|
|
249
|
+
File.join('remote/path', 'backup.tar.enc-aa'), file
|
|
250
|
+
)
|
|
251
|
+
# second yield
|
|
252
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
253
|
+
"Storage::Dropbox started transferring " +
|
|
254
|
+
"'2011.12.31.11.00.02.backup.tar.enc-ab'."
|
|
255
|
+
)
|
|
256
|
+
File.expects(:open).in_sequence(s).with(
|
|
257
|
+
File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'), 'r'
|
|
258
|
+
).yields(file)
|
|
259
|
+
connection.expects(:put_file).in_sequence(s).with(
|
|
260
|
+
File.join('remote/path', 'backup.tar.enc-ab'), file
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
storage.send(:transfer!)
|
|
264
|
+
end
|
|
265
|
+
end # describe '#transfer!'
|
|
266
|
+
|
|
267
|
+
describe '#remove!' do
|
|
268
|
+
let(:package) { mock }
|
|
269
|
+
let(:connection) { mock }
|
|
270
|
+
let(:s) { sequence '' }
|
|
271
|
+
|
|
272
|
+
before do
|
|
273
|
+
storage.stubs(:storage_name).returns('Storage::Dropbox')
|
|
274
|
+
storage.stubs(:connection).returns(connection)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
it 'should remove the package files' do
|
|
278
|
+
storage.expects(:remote_path_for).in_sequence(s).with(package).
|
|
279
|
+
returns('remote/path')
|
|
280
|
+
storage.expects(:transferred_files_for).in_sequence(s).with(package).
|
|
281
|
+
multiple_yields(
|
|
282
|
+
['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
|
|
283
|
+
['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
|
|
284
|
+
)
|
|
285
|
+
# after both yields
|
|
286
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
|
287
|
+
"Storage::Dropbox started removing " +
|
|
288
|
+
"'2011.12.31.11.00.02.backup.tar.enc-aa' from Dropbox.\n" +
|
|
289
|
+
"Storage::Dropbox started removing " +
|
|
290
|
+
"'2011.12.31.11.00.02.backup.tar.enc-ab' from Dropbox."
|
|
291
|
+
)
|
|
292
|
+
connection.expects(:file_delete).in_sequence(s).with('remote/path')
|
|
293
|
+
|
|
294
|
+
storage.send(:remove!, package)
|
|
295
|
+
end
|
|
296
|
+
end # describe '#remove!'
|
|
297
|
+
|
|
298
|
+
describe '#cached_file' do
|
|
299
|
+
it 'should return the path to the cache file' do
|
|
300
|
+
storage.send(:cached_file).should ==
|
|
301
|
+
File.join(Backup::Config.cache_path, 'my_api_keymy_api_secret')
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
describe '#cache_exists?' do
|
|
306
|
+
it 'should check if #cached_file exists' do
|
|
307
|
+
storage.expects(:cached_file).returns('/path/to/cache_file')
|
|
308
|
+
File.expects(:exist?).with('/path/to/cache_file')
|
|
309
|
+
|
|
310
|
+
storage.send(:cache_exists?)
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
describe '#write_cache!' do
|
|
315
|
+
let(:session) { mock }
|
|
316
|
+
let(:cache_file) { mock }
|
|
317
|
+
|
|
318
|
+
it 'should write a serialized session to file' do
|
|
319
|
+
storage.expects(:cached_file).returns('/path/to/cache_file')
|
|
320
|
+
session.expects(:serialize).returns('serialized_data')
|
|
321
|
+
|
|
322
|
+
File.expects(:open).with('/path/to/cache_file', 'w').yields(cache_file)
|
|
323
|
+
cache_file.expects(:write).with('serialized_data')
|
|
324
|
+
|
|
325
|
+
storage.send(:write_cache!, session)
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
describe '#create_write_and_return_new_session!' do
|
|
330
|
+
let(:session) { mock }
|
|
331
|
+
let(:template) { mock }
|
|
332
|
+
let(:s) { sequence '' }
|
|
333
|
+
|
|
334
|
+
before do
|
|
335
|
+
storage.stubs(:cached_file).returns('/path/to/cache_file')
|
|
336
|
+
|
|
337
|
+
DropboxSession.expects(:new).in_sequence(s).
|
|
338
|
+
with('my_api_key', 'my_api_secret').returns(session)
|
|
339
|
+
session.expects(:get_request_token).in_sequence(s)
|
|
340
|
+
Backup::Template.expects(:new).in_sequence(s).with(
|
|
341
|
+
{:session => session, :cached_file => '/path/to/cache_file'}
|
|
342
|
+
).returns(template)
|
|
343
|
+
template.expects(:render).in_sequence(s).with(
|
|
344
|
+
'storage/dropbox/authorization_url.erb'
|
|
345
|
+
)
|
|
346
|
+
Timeout.expects(:timeout).in_sequence(s).with(180).yields
|
|
347
|
+
STDIN.expects(:gets).in_sequence(s)
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
context 'when session is authenticated' do
|
|
351
|
+
before do
|
|
352
|
+
session.expects(:get_access_token).in_sequence(s)
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
it 'should cache and return the new session' do
|
|
356
|
+
template.expects(:render).in_sequence(s).with(
|
|
357
|
+
'storage/dropbox/authorized.erb'
|
|
358
|
+
)
|
|
359
|
+
storage.expects(:write_cache!).in_sequence(s).with(session)
|
|
360
|
+
template.expects(:render).in_sequence(s).with(
|
|
361
|
+
'storage/dropbox/cache_file_written.erb'
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
storage.send(:create_write_and_return_new_session!).should be(session)
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
context 'when session is not authenticated' do
|
|
369
|
+
before do
|
|
370
|
+
session.expects(:get_access_token).in_sequence(s).raises('error message')
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
it 'should wrap and re-raise the error' do
|
|
374
|
+
template.expects(:render).with('storage/dropbox/authorized.erb').never
|
|
375
|
+
storage.expects(:write_cache!).never
|
|
376
|
+
template.expects(:render).with('storage/dropbox/cache_file_written.erb').never
|
|
377
|
+
|
|
378
|
+
expect do
|
|
379
|
+
storage.send(:create_write_and_return_new_session!)
|
|
380
|
+
end.to raise_error {|err|
|
|
381
|
+
err.should be_an_instance_of(
|
|
382
|
+
Backup::Errors::Storage::Dropbox::AuthenticationError
|
|
383
|
+
)
|
|
384
|
+
err.message.should == 'Storage::Dropbox::AuthenticationError: ' +
|
|
385
|
+
"Could not create or authenticate a new session\n" +
|
|
386
|
+
" Reason: RuntimeError\n" +
|
|
387
|
+
" error message"
|
|
388
|
+
}
|
|
389
|
+
end
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
describe 'deprecations' do
|
|
394
|
+
after do
|
|
395
|
+
Backup::Storage::Dropbox.clear_defaults!
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
describe '#email' do
|
|
399
|
+
before do
|
|
400
|
+
Backup::Logger.expects(:warn).with do |err|
|
|
401
|
+
err.message.should match(
|
|
402
|
+
"Dropbox#email has been deprecated as of backup v.3.0.17"
|
|
403
|
+
)
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
context 'when set directly' do
|
|
408
|
+
it 'should issue a deprecation warning' do
|
|
409
|
+
Backup::Storage::Dropbox.new(model) do |storage|
|
|
410
|
+
storage.email = 'foo'
|
|
411
|
+
end
|
|
412
|
+
end
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
context 'when set as a default' do
|
|
416
|
+
it 'should issue a deprecation warning' do
|
|
417
|
+
Backup::Storage::Dropbox.defaults do |storage|
|
|
418
|
+
storage.email = 'foo'
|
|
419
|
+
end
|
|
420
|
+
Backup::Storage::Dropbox.new(model)
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
describe '#password' do
|
|
426
|
+
before do
|
|
427
|
+
Backup::Logger.expects(:warn).with do |err|
|
|
428
|
+
err.message.should match(
|
|
429
|
+
"Dropbox#password has been deprecated as of backup v.3.0.17"
|
|
430
|
+
)
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
context 'when set directly' do
|
|
435
|
+
it 'should issue a deprecation warning' do
|
|
436
|
+
Backup::Storage::Dropbox.new(model) do |storage|
|
|
437
|
+
storage.password = 'foo'
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
context 'when set as a default' do
|
|
443
|
+
it 'should issue a deprecation warning' do
|
|
444
|
+
Backup::Storage::Dropbox.defaults do |storage|
|
|
445
|
+
storage.password = 'foo'
|
|
446
|
+
end
|
|
447
|
+
Backup::Storage::Dropbox.new(model)
|
|
448
|
+
end
|
|
449
|
+
end
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
describe '#timeout' do
|
|
453
|
+
before do
|
|
454
|
+
Backup::Logger.expects(:warn).with do |err|
|
|
455
|
+
err.message.should match(
|
|
456
|
+
"Dropbox#timeout has been deprecated as of backup v.3.0.21"
|
|
457
|
+
)
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
context 'when set directly' do
|
|
462
|
+
it 'should issue a deprecation warning' do
|
|
463
|
+
Backup::Storage::Dropbox.new(model) do |storage|
|
|
464
|
+
storage.timeout = 'foo'
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
context 'when set as a default' do
|
|
470
|
+
it 'should issue a deprecation warning' do
|
|
471
|
+
Backup::Storage::Dropbox.defaults do |storage|
|
|
472
|
+
storage.timeout = 'foo'
|
|
473
|
+
end
|
|
474
|
+
Backup::Storage::Dropbox.new(model)
|
|
475
|
+
end
|
|
476
|
+
end
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
end
|