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,181 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../../../spec_helper.rb', __FILE__)
|
3
|
+
|
4
|
+
describe 'Backup::Syncer::Cloud::CloudFiles' do
|
5
|
+
let(:syncer) do
|
6
|
+
Backup::Syncer::Cloud::CloudFiles.new do |cf|
|
7
|
+
cf.api_key = 'my_api_key'
|
8
|
+
cf.username = 'my_username'
|
9
|
+
cf.container = 'my_container'
|
10
|
+
cf.auth_url = 'my_auth_url'
|
11
|
+
cf.servicenet = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should be a subclass of Syncer::Cloud::Base' do
|
16
|
+
Backup::Syncer::Cloud::CloudFiles.
|
17
|
+
superclass.should == Backup::Syncer::Cloud::Base
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#initialize' do
|
21
|
+
after { Backup::Syncer::Cloud::CloudFiles.clear_defaults! }
|
22
|
+
|
23
|
+
it 'should load pre-configured defaults through Syncer::Cloud::Base' do
|
24
|
+
Backup::Syncer::Cloud::CloudFiles.any_instance.expects(:load_defaults!)
|
25
|
+
syncer
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should strip any leading slash in path' do
|
29
|
+
syncer = Backup::Syncer::Cloud::CloudFiles.new do |cloud|
|
30
|
+
cloud.path = '/cleaned/path'
|
31
|
+
end
|
32
|
+
syncer.path.should == 'cleaned/path'
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when no pre-configured defaults have been set' do
|
36
|
+
it 'should use the values given' do
|
37
|
+
syncer.api_key.should == 'my_api_key'
|
38
|
+
syncer.username.should == 'my_username'
|
39
|
+
syncer.container.should == 'my_container'
|
40
|
+
syncer.auth_url.should == 'my_auth_url'
|
41
|
+
syncer.servicenet.should == true
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should use default values if none are given' do
|
45
|
+
syncer = Backup::Syncer::Cloud::CloudFiles.new
|
46
|
+
|
47
|
+
# from Syncer::Base
|
48
|
+
syncer.path.should == 'backups'
|
49
|
+
syncer.mirror.should == false
|
50
|
+
syncer.directories.should == []
|
51
|
+
|
52
|
+
# from Syncer::Cloud::Base
|
53
|
+
syncer.concurrency_type.should == false
|
54
|
+
syncer.concurrency_level.should == 2
|
55
|
+
|
56
|
+
syncer.api_key.should == nil
|
57
|
+
syncer.username.should == nil
|
58
|
+
syncer.container.should == nil
|
59
|
+
syncer.auth_url.should == nil
|
60
|
+
syncer.servicenet.should == nil
|
61
|
+
end
|
62
|
+
end # context 'when no pre-configured defaults have been set'
|
63
|
+
|
64
|
+
context 'when pre-configured defaults have been set' do
|
65
|
+
before do
|
66
|
+
Backup::Syncer::Cloud::CloudFiles.defaults do |cloud|
|
67
|
+
cloud.api_key = 'default_api_key'
|
68
|
+
cloud.username = 'default_username'
|
69
|
+
cloud.container = 'default_container'
|
70
|
+
cloud.auth_url = 'default_auth_url'
|
71
|
+
cloud.servicenet = 'default_servicenet'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should use pre-configured defaults' do
|
76
|
+
syncer = Backup::Syncer::Cloud::CloudFiles.new
|
77
|
+
|
78
|
+
# from Syncer::Base
|
79
|
+
syncer.path.should == 'backups'
|
80
|
+
syncer.mirror.should == false
|
81
|
+
syncer.directories.should == []
|
82
|
+
|
83
|
+
# from Syncer::Cloud::Base
|
84
|
+
syncer.concurrency_type.should == false
|
85
|
+
syncer.concurrency_level.should == 2
|
86
|
+
|
87
|
+
syncer.api_key.should == 'default_api_key'
|
88
|
+
syncer.username.should == 'default_username'
|
89
|
+
syncer.container.should == 'default_container'
|
90
|
+
syncer.auth_url.should == 'default_auth_url'
|
91
|
+
syncer.servicenet.should == 'default_servicenet'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should override pre-configured defaults' do
|
95
|
+
syncer = Backup::Syncer::Cloud::CloudFiles.new do |cloud|
|
96
|
+
cloud.path = 'new_path'
|
97
|
+
cloud.mirror = 'new_mirror'
|
98
|
+
cloud.concurrency_type = 'new_concurrency_type'
|
99
|
+
cloud.concurrency_level = 'new_concurrency_level'
|
100
|
+
|
101
|
+
cloud.api_key = 'new_api_key'
|
102
|
+
cloud.username = 'new_username'
|
103
|
+
cloud.container = 'new_container'
|
104
|
+
cloud.auth_url = 'new_auth_url'
|
105
|
+
cloud.servicenet = 'new_servicenet'
|
106
|
+
end
|
107
|
+
|
108
|
+
syncer.path.should == 'new_path'
|
109
|
+
syncer.mirror.should == 'new_mirror'
|
110
|
+
syncer.directories.should == []
|
111
|
+
syncer.concurrency_type.should == 'new_concurrency_type'
|
112
|
+
syncer.concurrency_level.should == 'new_concurrency_level'
|
113
|
+
|
114
|
+
syncer.api_key.should == 'new_api_key'
|
115
|
+
syncer.username.should == 'new_username'
|
116
|
+
syncer.container.should == 'new_container'
|
117
|
+
syncer.auth_url.should == 'new_auth_url'
|
118
|
+
syncer.servicenet.should == 'new_servicenet'
|
119
|
+
end
|
120
|
+
end # context 'when pre-configured defaults have been set'
|
121
|
+
end # describe '#initialize'
|
122
|
+
|
123
|
+
describe '#connection' do
|
124
|
+
let(:connection) { mock }
|
125
|
+
|
126
|
+
before do
|
127
|
+
Fog::Storage.expects(:new).once.with(
|
128
|
+
:provider => 'Rackspace',
|
129
|
+
:rackspace_username => 'my_username',
|
130
|
+
:rackspace_api_key => 'my_api_key',
|
131
|
+
:rackspace_auth_url => 'my_auth_url',
|
132
|
+
:rackspace_servicenet => true
|
133
|
+
).returns(connection)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should establish and re-use the connection' do
|
137
|
+
syncer.send(:connection).should == connection
|
138
|
+
syncer.instance_variable_get(:@connection).should == connection
|
139
|
+
syncer.send(:connection).should == connection
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#repository_object' do
|
144
|
+
let(:connection) { mock }
|
145
|
+
let(:directories) { mock }
|
146
|
+
let(:container) { mock }
|
147
|
+
|
148
|
+
before do
|
149
|
+
syncer.stubs(:connection).returns(connection)
|
150
|
+
connection.stubs(:directories).returns(directories)
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when the @container does not exist' do
|
154
|
+
before do
|
155
|
+
directories.expects(:get).once.with('my_container').returns(nil)
|
156
|
+
directories.expects(:create).once.with(
|
157
|
+
:key => 'my_container'
|
158
|
+
).returns(container)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should create and re-use the container' do
|
162
|
+
syncer.send(:repository_object).should == container
|
163
|
+
syncer.instance_variable_get(:@repository_object).should == container
|
164
|
+
syncer.send(:repository_object).should == container
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'when the @container does exist' do
|
169
|
+
before do
|
170
|
+
directories.expects(:get).once.with('my_container').returns(container)
|
171
|
+
directories.expects(:create).never
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should retrieve and re-use the container' do
|
175
|
+
syncer.send(:repository_object).should == container
|
176
|
+
syncer.instance_variable_get(:@repository_object).should == container
|
177
|
+
syncer.send(:repository_object).should == container
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../../../spec_helper.rb', __FILE__)
|
3
|
+
|
4
|
+
describe 'Backup::Syncer::Cloud::S3' do
|
5
|
+
let(:syncer) do
|
6
|
+
Backup::Syncer::Cloud::S3.new do |s3|
|
7
|
+
s3.access_key_id = 'my_access_key_id'
|
8
|
+
s3.secret_access_key = 'my_secret_access_key'
|
9
|
+
s3.bucket = 'my_bucket'
|
10
|
+
s3.region = 'my_region'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should be a subclass of Syncer::Cloud::Base' do
|
15
|
+
Backup::Syncer::Cloud::S3.
|
16
|
+
superclass.should == Backup::Syncer::Cloud::Base
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#initialize' do
|
20
|
+
after { Backup::Syncer::Cloud::S3.clear_defaults! }
|
21
|
+
|
22
|
+
it 'should load pre-configured defaults through Syncer::Cloud::Base' do
|
23
|
+
Backup::Syncer::Cloud::S3.any_instance.expects(:load_defaults!)
|
24
|
+
syncer
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should strip any leading slash in path' do
|
28
|
+
syncer = Backup::Syncer::Cloud::S3.new do |cloud|
|
29
|
+
cloud.path = '/cleaned/path'
|
30
|
+
end
|
31
|
+
syncer.path.should == 'cleaned/path'
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when no pre-configured defaults have been set' do
|
35
|
+
it 'should use the values given' do
|
36
|
+
syncer.access_key_id.should == 'my_access_key_id'
|
37
|
+
syncer.secret_access_key.should == 'my_secret_access_key'
|
38
|
+
syncer.bucket.should == 'my_bucket'
|
39
|
+
syncer.region.should == 'my_region'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should use default values if none are given' do
|
43
|
+
syncer = Backup::Syncer::Cloud::S3.new
|
44
|
+
|
45
|
+
# from Syncer::Base
|
46
|
+
syncer.path.should == 'backups'
|
47
|
+
syncer.mirror.should == false
|
48
|
+
syncer.directories.should == []
|
49
|
+
|
50
|
+
# from Syncer::Cloud::Base
|
51
|
+
syncer.concurrency_type.should == false
|
52
|
+
syncer.concurrency_level.should == 2
|
53
|
+
|
54
|
+
syncer.access_key_id.should be_nil
|
55
|
+
syncer.secret_access_key.should be_nil
|
56
|
+
syncer.bucket.should be_nil
|
57
|
+
syncer.region.should be_nil
|
58
|
+
end
|
59
|
+
end # context 'when no pre-configured defaults have been set'
|
60
|
+
|
61
|
+
context 'when pre-configured defaults have been set' do
|
62
|
+
before do
|
63
|
+
Backup::Syncer::Cloud::S3.defaults do |cloud|
|
64
|
+
cloud.access_key_id = 'default_access_key_id'
|
65
|
+
cloud.secret_access_key = 'default_secret_access_key'
|
66
|
+
cloud.bucket = 'default_bucket'
|
67
|
+
cloud.region = 'default_region'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should use pre-configured defaults' do
|
72
|
+
syncer = Backup::Syncer::Cloud::S3.new
|
73
|
+
|
74
|
+
# from Syncer::Base
|
75
|
+
syncer.path.should == 'backups'
|
76
|
+
syncer.mirror.should == false
|
77
|
+
syncer.directories.should == []
|
78
|
+
|
79
|
+
# from Syncer::Cloud::Base
|
80
|
+
syncer.concurrency_type.should == false
|
81
|
+
syncer.concurrency_level.should == 2
|
82
|
+
|
83
|
+
syncer.access_key_id.should == 'default_access_key_id'
|
84
|
+
syncer.secret_access_key.should == 'default_secret_access_key'
|
85
|
+
syncer.bucket.should == 'default_bucket'
|
86
|
+
syncer.region.should == 'default_region'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should override pre-configured defaults' do
|
90
|
+
syncer = Backup::Syncer::Cloud::S3.new do |cloud|
|
91
|
+
cloud.path = 'new_path'
|
92
|
+
cloud.mirror = 'new_mirror'
|
93
|
+
cloud.concurrency_type = 'new_concurrency_type'
|
94
|
+
cloud.concurrency_level = 'new_concurrency_level'
|
95
|
+
|
96
|
+
cloud.access_key_id = 'new_access_key_id'
|
97
|
+
cloud.secret_access_key = 'new_secret_access_key'
|
98
|
+
cloud.bucket = 'new_bucket'
|
99
|
+
cloud.region = 'new_region'
|
100
|
+
end
|
101
|
+
|
102
|
+
syncer.path.should == 'new_path'
|
103
|
+
syncer.mirror.should == 'new_mirror'
|
104
|
+
syncer.directories.should == []
|
105
|
+
syncer.concurrency_type.should == 'new_concurrency_type'
|
106
|
+
syncer.concurrency_level.should == 'new_concurrency_level'
|
107
|
+
|
108
|
+
syncer.access_key_id.should == 'new_access_key_id'
|
109
|
+
syncer.secret_access_key.should == 'new_secret_access_key'
|
110
|
+
syncer.bucket.should == 'new_bucket'
|
111
|
+
syncer.region.should == 'new_region'
|
112
|
+
end
|
113
|
+
end # context 'when pre-configured defaults have been set'
|
114
|
+
end # describe '#initialize'
|
115
|
+
|
116
|
+
describe '#connection' do
|
117
|
+
let(:connection) { mock }
|
118
|
+
|
119
|
+
before do
|
120
|
+
Fog::Storage.expects(:new).once.with(
|
121
|
+
:provider => 'AWS',
|
122
|
+
:aws_access_key_id => 'my_access_key_id',
|
123
|
+
:aws_secret_access_key => 'my_secret_access_key',
|
124
|
+
:region => 'my_region'
|
125
|
+
).returns(connection)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should establish and re-use the connection' do
|
129
|
+
syncer.send(:connection).should == connection
|
130
|
+
syncer.instance_variable_get(:@connection).should == connection
|
131
|
+
syncer.send(:connection).should == connection
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#repository_object' do
|
136
|
+
let(:connection) { mock }
|
137
|
+
let(:directories) { mock }
|
138
|
+
let(:bucket) { mock }
|
139
|
+
|
140
|
+
before do
|
141
|
+
syncer.stubs(:connection).returns(connection)
|
142
|
+
connection.stubs(:directories).returns(directories)
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when the @bucket does not exist' do
|
146
|
+
before do
|
147
|
+
directories.expects(:get).once.with('my_bucket').returns(nil)
|
148
|
+
directories.expects(:create).once.with(
|
149
|
+
:key => 'my_bucket',
|
150
|
+
:location => 'my_region'
|
151
|
+
).returns(bucket)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should create and re-use the bucket' do
|
155
|
+
syncer.send(:repository_object).should == bucket
|
156
|
+
syncer.instance_variable_get(:@repository_object).should == bucket
|
157
|
+
syncer.send(:repository_object).should == bucket
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'when the @bucket does exist' do
|
162
|
+
before do
|
163
|
+
directories.expects(:get).once.with('my_bucket').returns(bucket)
|
164
|
+
directories.expects(:create).never
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should retrieve and re-use the bucket' do
|
168
|
+
syncer.send(:repository_object).should == bucket
|
169
|
+
syncer.instance_variable_get(:@repository_object).should == bucket
|
170
|
+
syncer.send(:repository_object).should == bucket
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Backup::Syncer::RSync::Base' do
|
6
|
+
let(:syncer) { Backup::Syncer::RSync::Base.new }
|
7
|
+
|
8
|
+
it 'should be a subclass of Syncer::Base' do
|
9
|
+
Backup::Syncer::RSync::Base.
|
10
|
+
superclass.should == Backup::Syncer::Base
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#initialize' do
|
14
|
+
after { Backup::Syncer::RSync::Base.clear_defaults! }
|
15
|
+
|
16
|
+
it 'should load pre-configured defaults through Syncer::Base' do
|
17
|
+
Backup::Syncer::RSync::Base.any_instance.expects(:load_defaults!)
|
18
|
+
syncer
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when no pre-configured defaults have been set' do
|
22
|
+
it 'should use default values' do
|
23
|
+
syncer.path.should == 'backups'
|
24
|
+
syncer.mirror.should == false
|
25
|
+
syncer.directories.should == []
|
26
|
+
syncer.additional_options.should == []
|
27
|
+
end
|
28
|
+
end # context 'when no pre-configured defaults have been set'
|
29
|
+
|
30
|
+
context 'when pre-configured defaults have been set' do
|
31
|
+
before do
|
32
|
+
Backup::Syncer::RSync::Base.defaults do |rsync|
|
33
|
+
rsync.path = 'some_path'
|
34
|
+
rsync.mirror = 'some_mirror'
|
35
|
+
rsync.additional_options = 'some_additional_options'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should use pre-configured defaults' do
|
40
|
+
syncer.path.should == 'some_path'
|
41
|
+
syncer.mirror.should == 'some_mirror'
|
42
|
+
syncer.directories.should == []
|
43
|
+
syncer.additional_options.should == 'some_additional_options'
|
44
|
+
end
|
45
|
+
end # context 'when pre-configured defaults have been set'
|
46
|
+
end # describe '#initialize'
|
47
|
+
|
48
|
+
describe '#directory_options' do
|
49
|
+
before do
|
50
|
+
syncer.instance_variable_set(
|
51
|
+
:@directories, ['/some/directory', '/another/directory']
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should return the directories for use in the command line' do
|
56
|
+
syncer.send(:directories_option).should ==
|
57
|
+
"'/some/directory' '/another/directory'"
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when @directories have relative paths' do
|
61
|
+
before do
|
62
|
+
syncer.instance_variable_set(
|
63
|
+
:@directories, ['/some/directory', '/another/directory',
|
64
|
+
'relative/path', '~/home/path']
|
65
|
+
)
|
66
|
+
end
|
67
|
+
it 'should expand relative paths' do
|
68
|
+
syncer.send(:directories_option).should ==
|
69
|
+
"'/some/directory' '/another/directory' " +
|
70
|
+
"'#{ File.expand_path('relative/path') }' " +
|
71
|
+
"'#{ File.expand_path('~/home/path') }'"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#mirror_option' do
|
77
|
+
context 'when @mirror is true' do
|
78
|
+
before { syncer.mirror = true }
|
79
|
+
it 'should return the command line flag for mirroring' do
|
80
|
+
syncer.send(:mirror_option).should == '--delete'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when @mirror is false' do
|
85
|
+
before { syncer.mirror = false }
|
86
|
+
it 'should return nil' do
|
87
|
+
syncer.send(:mirror_option).should be_nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#archive_option' do
|
93
|
+
it 'should return the command line flag for archiving' do
|
94
|
+
syncer.send(:archive_option).should == '--archive'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|