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
@@ -3,136 +3,367 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Storage::Dropbox do
|
6
|
-
|
7
|
-
let(:
|
8
|
-
Backup::Storage::Dropbox.new do |db|
|
9
|
-
db.api_key
|
10
|
-
db.api_secret
|
11
|
-
db.keep
|
12
|
-
db.timeout = 500
|
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
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
describe '#initialize' do
|
16
|
+
it 'should set the correct values' do
|
17
|
+
storage.api_key.should == 'my_api_key'
|
18
|
+
storage.api_secret.should == 'my_api_secret'
|
19
|
+
storage.access_type.should == :app_folder
|
20
|
+
storage.path.should == 'backups'
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should have defined the configuration properly' do
|
27
|
-
db.api_key.should == 'my_api_key'
|
28
|
-
db.api_secret.should == 'my_secret'
|
29
|
-
db.path.should == 'backups'
|
30
|
-
db.keep.should == 20
|
31
|
-
db.timeout.should == 500
|
32
|
-
end
|
22
|
+
storage.storage_id.should be_nil
|
23
|
+
storage.keep.should == 5
|
24
|
+
end
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
db.
|
26
|
+
it 'should set a storage_id if given' do
|
27
|
+
db = Backup::Storage::Dropbox.new(model, 'my storage_id')
|
28
|
+
db.storage_id.should == 'my storage_id'
|
37
29
|
end
|
38
30
|
|
39
|
-
|
40
|
-
|
31
|
+
context 'when setting configuration defaults' do
|
32
|
+
after { Backup::Configuration::Storage::Dropbox.clear_defaults! }
|
41
33
|
|
42
|
-
|
43
|
-
|
34
|
+
it 'should use the configured defaults' do
|
35
|
+
Backup::Configuration::Storage::Dropbox.defaults do |db|
|
36
|
+
db.api_key = 'some_api_key'
|
37
|
+
db.api_secret = 'some_api_secret'
|
38
|
+
db.access_type = 'some_access_type'
|
39
|
+
db.path = 'some_path'
|
40
|
+
db.keep = 15
|
41
|
+
end
|
42
|
+
storage = Backup::Storage::Dropbox.new(model)
|
43
|
+
storage.api_key.should == 'some_api_key'
|
44
|
+
storage.api_secret.should == 'some_api_secret'
|
45
|
+
storage.access_type.should == 'some_access_type'
|
46
|
+
storage.path.should == 'some_path'
|
44
47
|
|
45
|
-
|
46
|
-
|
48
|
+
storage.storage_id.should be_nil
|
49
|
+
storage.keep.should == 15
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
it 'should override the configured defaults' do
|
53
|
+
Backup::Configuration::Storage::Dropbox.defaults do |db|
|
54
|
+
db.api_key = 'old_api_key'
|
55
|
+
db.api_secret = 'old_api_secret'
|
56
|
+
db.access_type = 'old_access_type'
|
57
|
+
db.path = 'old_path'
|
58
|
+
db.keep = 15
|
59
|
+
end
|
60
|
+
storage = Backup::Storage::Dropbox.new(model) do |db|
|
61
|
+
db.api_key = 'new_api_key'
|
62
|
+
db.api_secret = 'new_api_secret'
|
63
|
+
db.access_type = 'new_access_type'
|
64
|
+
db.path = 'new_path'
|
65
|
+
db.keep = 10
|
66
|
+
end
|
52
67
|
|
53
|
-
|
54
|
-
|
68
|
+
storage.api_key.should == 'new_api_key'
|
69
|
+
storage.api_secret.should == 'new_api_secret'
|
70
|
+
storage.access_type.should == 'new_access_type'
|
71
|
+
storage.path.should == 'new_path'
|
72
|
+
|
73
|
+
storage.storage_id.should be_nil
|
74
|
+
storage.keep.should == 10
|
75
|
+
end
|
76
|
+
end # context 'when setting configuration defaults'
|
77
|
+
|
78
|
+
end # describe '#initialize'
|
55
79
|
|
56
80
|
describe '#connection' do
|
57
|
-
|
58
|
-
|
81
|
+
let(:session) { mock }
|
82
|
+
let(:client) { mock }
|
83
|
+
let(:s) { sequence '' }
|
84
|
+
|
85
|
+
context 'when a cached session exists' do
|
86
|
+
before do
|
87
|
+
storage.expects(:cached_session).in_sequence(s).returns(session)
|
88
|
+
storage.expects(:create_write_and_return_new_session!).never
|
89
|
+
DropboxClient.expects(:new).in_sequence(s).
|
90
|
+
with(session, :app_folder).returns(client)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should use the cached session to create the client' do
|
94
|
+
storage.send(:connection).should be(client)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should return an already existing client' do
|
98
|
+
storage.send(:connection).should be(client)
|
99
|
+
storage.send(:connection).should be(client)
|
100
|
+
end
|
59
101
|
end
|
60
102
|
|
61
|
-
context
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
103
|
+
context 'when a cached session does not exist' do
|
104
|
+
before do
|
105
|
+
storage.expects(:cached_session).in_sequence(s).returns(false)
|
106
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
107
|
+
'Creating a new session!'
|
108
|
+
)
|
109
|
+
storage.expects(:create_write_and_return_new_session!).in_sequence(s).
|
110
|
+
returns(session)
|
111
|
+
DropboxClient.expects(:new).in_sequence(s).
|
112
|
+
with(session, :app_folder).returns(client)
|
113
|
+
end
|
69
114
|
|
70
|
-
|
71
|
-
|
115
|
+
it 'should create a new session and return the client' do
|
116
|
+
storage.send(:connection).should be(client)
|
117
|
+
end
|
72
118
|
|
73
|
-
|
74
|
-
|
119
|
+
it 'should return an already existing client' do
|
120
|
+
storage.send(:connection).should be(client)
|
121
|
+
storage.send(:connection).should be(client)
|
75
122
|
end
|
76
123
|
end
|
77
124
|
|
78
|
-
context
|
79
|
-
it
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
125
|
+
context 'when an error is raised creating a client for the session' do
|
126
|
+
it 'should wrap and raise the error' do
|
127
|
+
storage.stubs(:cached_session).returns(true)
|
128
|
+
DropboxClient.expects(:new).raises('error')
|
129
|
+
|
130
|
+
expect do
|
131
|
+
storage.send(:connection)
|
132
|
+
end.to raise_error {|err|
|
133
|
+
err.should be_an_instance_of(
|
134
|
+
Backup::Errors::Storage::Dropbox::ConnectionError
|
135
|
+
)
|
136
|
+
err.message.should ==
|
137
|
+
'Storage::Dropbox::ConnectionError: RuntimeError: error'
|
138
|
+
}
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end # describe '#connection'
|
143
|
+
|
144
|
+
describe '#cached_session' do
|
145
|
+
let(:session) { mock }
|
85
146
|
|
86
|
-
|
87
|
-
|
147
|
+
context 'when a cached session file exists' do
|
148
|
+
before do
|
149
|
+
storage.expects(:cache_exists?).returns(true)
|
150
|
+
storage.expects(:cached_file).returns('cached_file')
|
151
|
+
File.expects(:read).with('cached_file').returns('yaml_data')
|
88
152
|
end
|
89
153
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
154
|
+
context 'when the cached session is successfully loaded' do
|
155
|
+
it 'should return the sesssion' do
|
156
|
+
DropboxSession.expects(:deserialize).with('yaml_data').
|
157
|
+
returns(session)
|
158
|
+
Backup::Logger.expects(:message).with(
|
159
|
+
'Session data loaded from cache!'
|
160
|
+
)
|
96
161
|
|
97
|
-
|
98
|
-
|
162
|
+
storage.send(:cached_session).should be(session)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'when errors occur loading the session' do
|
167
|
+
it 'should log a warning and return false' do
|
168
|
+
DropboxSession.expects(:deserialize).with('yaml_data').
|
169
|
+
raises('error message')
|
170
|
+
Backup::Logger.expects(:warn).with do |err|
|
171
|
+
err.should be_an_instance_of(
|
172
|
+
Backup::Errors::Storage::Dropbox::CacheError
|
173
|
+
)
|
174
|
+
err.message.should == 'Storage::Dropbox::CacheError: ' +
|
175
|
+
"Could not read session data from cache.\n" +
|
176
|
+
" Cache data might be corrupt.\n" +
|
177
|
+
" Reason: RuntimeError\n" +
|
178
|
+
" error message"
|
179
|
+
end
|
180
|
+
|
181
|
+
expect do
|
182
|
+
storage.send(:cached_session).should be_false
|
183
|
+
end.not_to raise_error
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'when a cached session file does not exist' do
|
189
|
+
before { storage.stubs(:cache_exists?).returns(false) }
|
190
|
+
it 'should return false' do
|
191
|
+
storage.send(:cached_session).should be_false
|
99
192
|
end
|
100
193
|
end
|
101
194
|
end
|
102
195
|
|
103
196
|
describe '#transfer!' do
|
197
|
+
let(:connection) { mock }
|
198
|
+
let(:package) { mock }
|
199
|
+
let(:file) { mock }
|
200
|
+
let(:s) { sequence '' }
|
201
|
+
|
104
202
|
before do
|
105
|
-
|
106
|
-
|
203
|
+
storage.instance_variable_set(:@package, package)
|
204
|
+
storage.stubs(:storage_name).returns('Storage::Dropbox')
|
205
|
+
storage.stubs(:local_path).returns('/local/path')
|
206
|
+
storage.stubs(:connection).returns(connection)
|
107
207
|
end
|
108
208
|
|
109
|
-
it do
|
110
|
-
|
209
|
+
it 'should transfer the package files' do
|
210
|
+
storage.expects(:remote_path_for).in_sequence(s).with(package).
|
211
|
+
returns('remote/path')
|
212
|
+
storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
|
213
|
+
multiple_yields(
|
214
|
+
['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
|
215
|
+
['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
|
216
|
+
)
|
217
|
+
# first yield
|
218
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
219
|
+
"Storage::Dropbox started transferring " +
|
220
|
+
"'2011.12.31.11.00.02.backup.tar.enc-aa'."
|
221
|
+
)
|
222
|
+
File.expects(:open).in_sequence(s).with(
|
223
|
+
File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'), 'r'
|
224
|
+
).yields(file)
|
225
|
+
connection.expects(:put_file).in_sequence(s).with(
|
226
|
+
File.join('remote/path', 'backup.tar.enc-aa'), file
|
227
|
+
)
|
228
|
+
# second yield
|
229
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
111
230
|
"Storage::Dropbox started transferring " +
|
112
|
-
"'
|
231
|
+
"'2011.12.31.11.00.02.backup.tar.enc-ab'."
|
232
|
+
)
|
233
|
+
File.expects(:open).in_sequence(s).with(
|
234
|
+
File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'), 'r'
|
235
|
+
).yields(file)
|
236
|
+
connection.expects(:put_file).in_sequence(s).with(
|
237
|
+
File.join('remote/path', 'backup.tar.enc-ab'), file
|
113
238
|
)
|
114
|
-
|
239
|
+
|
240
|
+
storage.send(:transfer!)
|
241
|
+
end
|
242
|
+
end # describe '#transfer!'
|
243
|
+
|
244
|
+
describe '#remove!' do
|
245
|
+
let(:package) { mock }
|
246
|
+
let(:connection) { mock }
|
247
|
+
let(:s) { sequence '' }
|
248
|
+
|
249
|
+
before do
|
250
|
+
storage.stubs(:storage_name).returns('Storage::Dropbox')
|
251
|
+
storage.stubs(:connection).returns(connection)
|
115
252
|
end
|
116
253
|
|
117
|
-
it do
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
254
|
+
it 'should remove the package files' do
|
255
|
+
storage.expects(:remote_path_for).in_sequence(s).with(package).
|
256
|
+
returns('remote/path')
|
257
|
+
storage.expects(:transferred_files_for).in_sequence(s).with(package).
|
258
|
+
multiple_yields(
|
259
|
+
['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
|
260
|
+
['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
|
261
|
+
)
|
262
|
+
# after both yields
|
263
|
+
Backup::Logger.expects(:message).in_sequence(s).with(
|
264
|
+
"Storage::Dropbox started removing " +
|
265
|
+
"'2011.12.31.11.00.02.backup.tar.enc-aa' from Dropbox.\n" +
|
266
|
+
"Storage::Dropbox started removing " +
|
267
|
+
"'2011.12.31.11.00.02.backup.tar.enc-ab' from Dropbox."
|
123
268
|
)
|
269
|
+
connection.expects(:file_delete).in_sequence(s).with('remote/path')
|
124
270
|
|
125
|
-
|
271
|
+
storage.send(:remove!, package)
|
272
|
+
end
|
273
|
+
end # describe '#remove!'
|
274
|
+
|
275
|
+
describe '#cached_file' do
|
276
|
+
it 'should return the path to the cache file' do
|
277
|
+
storage.send(:cached_file).should ==
|
278
|
+
File.join(Backup::Config.cache_path, 'my_api_keymy_api_secret')
|
126
279
|
end
|
127
280
|
end
|
128
281
|
|
129
|
-
describe '#
|
130
|
-
it do
|
131
|
-
|
132
|
-
|
282
|
+
describe '#cache_exists?' do
|
283
|
+
it 'should check if #cached_file exists' do
|
284
|
+
storage.expects(:cached_file).returns('/path/to/cache_file')
|
285
|
+
File.expects(:exist?).with('/path/to/cache_file')
|
286
|
+
|
287
|
+
storage.send(:cache_exists?)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe '#write_cache!' do
|
292
|
+
let(:session) { mock }
|
293
|
+
let(:cache_file) { mock }
|
294
|
+
|
295
|
+
it 'should write a serialized session to file' do
|
296
|
+
storage.expects(:cached_file).returns('/path/to/cache_file')
|
297
|
+
session.expects(:serialize).returns('serialized_data')
|
298
|
+
|
299
|
+
File.expects(:open).with('/path/to/cache_file', 'w').yields(cache_file)
|
300
|
+
cache_file.expects(:write).with('serialized_data')
|
301
|
+
|
302
|
+
storage.send(:write_cache!, session)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
describe '#create_write_and_return_new_session!' do
|
307
|
+
let(:session) { mock }
|
308
|
+
let(:template) { mock }
|
309
|
+
let(:s) { sequence '' }
|
310
|
+
|
311
|
+
before do
|
312
|
+
storage.stubs(:cached_file).returns('/path/to/cache_file')
|
313
|
+
|
314
|
+
DropboxSession.expects(:new).in_sequence(s).
|
315
|
+
with('my_api_key', 'my_api_secret').returns(session)
|
316
|
+
session.expects(:get_request_token).in_sequence(s)
|
317
|
+
Backup::Template.expects(:new).in_sequence(s).with(
|
318
|
+
{:session => session, :cached_file => '/path/to/cache_file'}
|
319
|
+
).returns(template)
|
320
|
+
template.expects(:render).in_sequence(s).with(
|
321
|
+
'storage/dropbox/authorization_url.erb'
|
133
322
|
)
|
323
|
+
Timeout.expects(:timeout).in_sequence(s).with(180).yields
|
324
|
+
STDIN.expects(:gets).in_sequence(s)
|
325
|
+
end
|
326
|
+
|
327
|
+
context 'when session is authenticated' do
|
328
|
+
before do
|
329
|
+
session.expects(:get_access_token).in_sequence(s)
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'should cache and return the new session' do
|
333
|
+
template.expects(:render).in_sequence(s).with(
|
334
|
+
'storage/dropbox/authorized.erb'
|
335
|
+
)
|
336
|
+
storage.expects(:write_cache!).in_sequence(s).with(session)
|
337
|
+
template.expects(:render).in_sequence(s).with(
|
338
|
+
'storage/dropbox/cache_file_written.erb'
|
339
|
+
)
|
340
|
+
|
341
|
+
storage.send(:create_write_and_return_new_session!).should be(session)
|
342
|
+
end
|
343
|
+
end
|
134
344
|
|
135
|
-
|
345
|
+
context 'when session is not authenticated' do
|
346
|
+
before do
|
347
|
+
session.expects(:get_access_token).in_sequence(s).raises('error message')
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'should wrap and re-raise the error' do
|
351
|
+
template.expects(:render).with('storage/dropbox/authorized.erb').never
|
352
|
+
storage.expects(:write_cache!).never
|
353
|
+
template.expects(:render).with('storage/dropbox/cache_file_written.erb').never
|
354
|
+
|
355
|
+
expect do
|
356
|
+
storage.send(:create_write_and_return_new_session!)
|
357
|
+
end.to raise_error {|err|
|
358
|
+
err.should be_an_instance_of(
|
359
|
+
Backup::Errors::Storage::Dropbox::AuthenticationError
|
360
|
+
)
|
361
|
+
err.message.should == 'Storage::Dropbox::AuthenticationError: ' +
|
362
|
+
"Could not create or authenticate a new session\n" +
|
363
|
+
" Reason: RuntimeError\n" +
|
364
|
+
" error message"
|
365
|
+
}
|
366
|
+
end
|
136
367
|
end
|
137
368
|
end
|
138
369
|
|