backup_checksum 3.0.23

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.
Files changed (244) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +10 -0
  3. data/Gemfile +28 -0
  4. data/Gemfile.lock +130 -0
  5. data/Guardfile +21 -0
  6. data/LICENSE.md +24 -0
  7. data/README.md +476 -0
  8. data/backup_checksum.gemspec +32 -0
  9. data/bin/backup +11 -0
  10. data/lib/backup.rb +217 -0
  11. data/lib/backup/archive.rb +117 -0
  12. data/lib/backup/binder.rb +22 -0
  13. data/lib/backup/checksum/base.rb +44 -0
  14. data/lib/backup/checksum/shasum.rb +16 -0
  15. data/lib/backup/cleaner.rb +121 -0
  16. data/lib/backup/cli/helpers.rb +88 -0
  17. data/lib/backup/cli/utility.rb +247 -0
  18. data/lib/backup/compressor/base.rb +29 -0
  19. data/lib/backup/compressor/bzip2.rb +50 -0
  20. data/lib/backup/compressor/gzip.rb +47 -0
  21. data/lib/backup/compressor/lzma.rb +50 -0
  22. data/lib/backup/compressor/pbzip2.rb +56 -0
  23. data/lib/backup/config.rb +173 -0
  24. data/lib/backup/configuration/base.rb +15 -0
  25. data/lib/backup/configuration/checksum/base.rb +9 -0
  26. data/lib/backup/configuration/checksum/shasum.rb +9 -0
  27. data/lib/backup/configuration/compressor/base.rb +9 -0
  28. data/lib/backup/configuration/compressor/bzip2.rb +23 -0
  29. data/lib/backup/configuration/compressor/gzip.rb +23 -0
  30. data/lib/backup/configuration/compressor/lzma.rb +23 -0
  31. data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
  32. data/lib/backup/configuration/database/base.rb +19 -0
  33. data/lib/backup/configuration/database/mongodb.rb +49 -0
  34. data/lib/backup/configuration/database/mysql.rb +42 -0
  35. data/lib/backup/configuration/database/postgresql.rb +41 -0
  36. data/lib/backup/configuration/database/redis.rb +39 -0
  37. data/lib/backup/configuration/database/riak.rb +29 -0
  38. data/lib/backup/configuration/encryptor/base.rb +9 -0
  39. data/lib/backup/configuration/encryptor/gpg.rb +17 -0
  40. data/lib/backup/configuration/encryptor/open_ssl.rb +32 -0
  41. data/lib/backup/configuration/helpers.rb +52 -0
  42. data/lib/backup/configuration/notifier/base.rb +28 -0
  43. data/lib/backup/configuration/notifier/campfire.rb +25 -0
  44. data/lib/backup/configuration/notifier/hipchat.rb +41 -0
  45. data/lib/backup/configuration/notifier/mail.rb +112 -0
  46. data/lib/backup/configuration/notifier/presently.rb +25 -0
  47. data/lib/backup/configuration/notifier/prowl.rb +23 -0
  48. data/lib/backup/configuration/notifier/twitter.rb +21 -0
  49. data/lib/backup/configuration/storage/base.rb +18 -0
  50. data/lib/backup/configuration/storage/cloudfiles.rb +25 -0
  51. data/lib/backup/configuration/storage/dropbox.rb +58 -0
  52. data/lib/backup/configuration/storage/ftp.rb +29 -0
  53. data/lib/backup/configuration/storage/local.rb +17 -0
  54. data/lib/backup/configuration/storage/ninefold.rb +20 -0
  55. data/lib/backup/configuration/storage/rsync.rb +29 -0
  56. data/lib/backup/configuration/storage/s3.rb +25 -0
  57. data/lib/backup/configuration/storage/scp.rb +25 -0
  58. data/lib/backup/configuration/storage/sftp.rb +25 -0
  59. data/lib/backup/configuration/syncer/base.rb +10 -0
  60. data/lib/backup/configuration/syncer/cloud.rb +23 -0
  61. data/lib/backup/configuration/syncer/cloud_files.rb +30 -0
  62. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  63. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  64. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  65. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  66. data/lib/backup/configuration/syncer/s3.rb +23 -0
  67. data/lib/backup/database/base.rb +59 -0
  68. data/lib/backup/database/mongodb.rb +232 -0
  69. data/lib/backup/database/mysql.rb +163 -0
  70. data/lib/backup/database/postgresql.rb +146 -0
  71. data/lib/backup/database/redis.rb +139 -0
  72. data/lib/backup/database/riak.rb +69 -0
  73. data/lib/backup/dependency.rb +114 -0
  74. data/lib/backup/encryptor/base.rb +29 -0
  75. data/lib/backup/encryptor/gpg.rb +80 -0
  76. data/lib/backup/encryptor/open_ssl.rb +72 -0
  77. data/lib/backup/errors.rb +124 -0
  78. data/lib/backup/logger.rb +152 -0
  79. data/lib/backup/model.rb +386 -0
  80. data/lib/backup/notifier/base.rb +81 -0
  81. data/lib/backup/notifier/campfire.rb +168 -0
  82. data/lib/backup/notifier/hipchat.rb +99 -0
  83. data/lib/backup/notifier/mail.rb +206 -0
  84. data/lib/backup/notifier/presently.rb +88 -0
  85. data/lib/backup/notifier/prowl.rb +65 -0
  86. data/lib/backup/notifier/twitter.rb +70 -0
  87. data/lib/backup/package.rb +51 -0
  88. data/lib/backup/packager.rb +108 -0
  89. data/lib/backup/pipeline.rb +107 -0
  90. data/lib/backup/splitter.rb +75 -0
  91. data/lib/backup/storage/base.rb +119 -0
  92. data/lib/backup/storage/cloudfiles.rb +87 -0
  93. data/lib/backup/storage/cycler.rb +117 -0
  94. data/lib/backup/storage/dropbox.rb +181 -0
  95. data/lib/backup/storage/ftp.rb +119 -0
  96. data/lib/backup/storage/local.rb +82 -0
  97. data/lib/backup/storage/ninefold.rb +116 -0
  98. data/lib/backup/storage/rsync.rb +149 -0
  99. data/lib/backup/storage/s3.rb +94 -0
  100. data/lib/backup/storage/scp.rb +99 -0
  101. data/lib/backup/storage/sftp.rb +108 -0
  102. data/lib/backup/syncer/base.rb +42 -0
  103. data/lib/backup/syncer/cloud.rb +190 -0
  104. data/lib/backup/syncer/cloud_files.rb +56 -0
  105. data/lib/backup/syncer/rsync/base.rb +52 -0
  106. data/lib/backup/syncer/rsync/local.rb +53 -0
  107. data/lib/backup/syncer/rsync/pull.rb +38 -0
  108. data/lib/backup/syncer/rsync/push.rb +113 -0
  109. data/lib/backup/syncer/s3.rb +47 -0
  110. data/lib/backup/template.rb +46 -0
  111. data/lib/backup/version.rb +43 -0
  112. data/spec/archive_spec.rb +335 -0
  113. data/spec/cleaner_spec.rb +304 -0
  114. data/spec/cli/helpers_spec.rb +176 -0
  115. data/spec/cli/utility_spec.rb +363 -0
  116. data/spec/compressor/base_spec.rb +31 -0
  117. data/spec/compressor/bzip2_spec.rb +83 -0
  118. data/spec/compressor/gzip_spec.rb +83 -0
  119. data/spec/compressor/lzma_spec.rb +83 -0
  120. data/spec/compressor/pbzip2_spec.rb +124 -0
  121. data/spec/config_spec.rb +321 -0
  122. data/spec/configuration/base_spec.rb +35 -0
  123. data/spec/configuration/compressor/bzip2_spec.rb +29 -0
  124. data/spec/configuration/compressor/gzip_spec.rb +29 -0
  125. data/spec/configuration/compressor/lzma_spec.rb +29 -0
  126. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  127. data/spec/configuration/database/base_spec.rb +17 -0
  128. data/spec/configuration/database/mongodb_spec.rb +56 -0
  129. data/spec/configuration/database/mysql_spec.rb +53 -0
  130. data/spec/configuration/database/postgresql_spec.rb +53 -0
  131. data/spec/configuration/database/redis_spec.rb +50 -0
  132. data/spec/configuration/database/riak_spec.rb +35 -0
  133. data/spec/configuration/encryptor/gpg_spec.rb +26 -0
  134. data/spec/configuration/encryptor/open_ssl_spec.rb +35 -0
  135. data/spec/configuration/notifier/base_spec.rb +32 -0
  136. data/spec/configuration/notifier/campfire_spec.rb +32 -0
  137. data/spec/configuration/notifier/hipchat_spec.rb +44 -0
  138. data/spec/configuration/notifier/mail_spec.rb +71 -0
  139. data/spec/configuration/notifier/presently_spec.rb +35 -0
  140. data/spec/configuration/notifier/prowl_spec.rb +29 -0
  141. data/spec/configuration/notifier/twitter_spec.rb +35 -0
  142. data/spec/configuration/storage/cloudfiles_spec.rb +41 -0
  143. data/spec/configuration/storage/dropbox_spec.rb +38 -0
  144. data/spec/configuration/storage/ftp_spec.rb +44 -0
  145. data/spec/configuration/storage/local_spec.rb +29 -0
  146. data/spec/configuration/storage/ninefold_spec.rb +32 -0
  147. data/spec/configuration/storage/rsync_spec.rb +41 -0
  148. data/spec/configuration/storage/s3_spec.rb +38 -0
  149. data/spec/configuration/storage/scp_spec.rb +41 -0
  150. data/spec/configuration/storage/sftp_spec.rb +41 -0
  151. data/spec/configuration/syncer/cloud_files_spec.rb +44 -0
  152. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  153. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  154. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  155. data/spec/configuration/syncer/rsync/push_spec.rb +43 -0
  156. data/spec/configuration/syncer/s3_spec.rb +38 -0
  157. data/spec/database/base_spec.rb +54 -0
  158. data/spec/database/mongodb_spec.rb +428 -0
  159. data/spec/database/mysql_spec.rb +335 -0
  160. data/spec/database/postgresql_spec.rb +278 -0
  161. data/spec/database/redis_spec.rb +260 -0
  162. data/spec/database/riak_spec.rb +108 -0
  163. data/spec/dependency_spec.rb +49 -0
  164. data/spec/encryptor/base_spec.rb +30 -0
  165. data/spec/encryptor/gpg_spec.rb +134 -0
  166. data/spec/encryptor/open_ssl_spec.rb +129 -0
  167. data/spec/errors_spec.rb +306 -0
  168. data/spec/logger_spec.rb +363 -0
  169. data/spec/model_spec.rb +649 -0
  170. data/spec/notifier/base_spec.rb +89 -0
  171. data/spec/notifier/campfire_spec.rb +199 -0
  172. data/spec/notifier/hipchat_spec.rb +188 -0
  173. data/spec/notifier/mail_spec.rb +280 -0
  174. data/spec/notifier/presently_spec.rb +181 -0
  175. data/spec/notifier/prowl_spec.rb +117 -0
  176. data/spec/notifier/twitter_spec.rb +132 -0
  177. data/spec/package_spec.rb +61 -0
  178. data/spec/packager_spec.rb +225 -0
  179. data/spec/pipeline_spec.rb +257 -0
  180. data/spec/spec_helper.rb +59 -0
  181. data/spec/splitter_spec.rb +120 -0
  182. data/spec/storage/base_spec.rb +160 -0
  183. data/spec/storage/cloudfiles_spec.rb +230 -0
  184. data/spec/storage/cycler_spec.rb +239 -0
  185. data/spec/storage/dropbox_spec.rb +370 -0
  186. data/spec/storage/ftp_spec.rb +247 -0
  187. data/spec/storage/local_spec.rb +235 -0
  188. data/spec/storage/ninefold_spec.rb +319 -0
  189. data/spec/storage/rsync_spec.rb +345 -0
  190. data/spec/storage/s3_spec.rb +221 -0
  191. data/spec/storage/scp_spec.rb +209 -0
  192. data/spec/storage/sftp_spec.rb +220 -0
  193. data/spec/syncer/base_spec.rb +22 -0
  194. data/spec/syncer/cloud_files_spec.rb +192 -0
  195. data/spec/syncer/rsync/base_spec.rb +118 -0
  196. data/spec/syncer/rsync/local_spec.rb +121 -0
  197. data/spec/syncer/rsync/pull_spec.rb +90 -0
  198. data/spec/syncer/rsync/push_spec.rb +327 -0
  199. data/spec/syncer/s3_spec.rb +192 -0
  200. data/spec/version_spec.rb +21 -0
  201. data/templates/cli/utility/archive +25 -0
  202. data/templates/cli/utility/compressor/bzip2 +7 -0
  203. data/templates/cli/utility/compressor/gzip +7 -0
  204. data/templates/cli/utility/compressor/lzma +7 -0
  205. data/templates/cli/utility/compressor/pbzip2 +7 -0
  206. data/templates/cli/utility/config +31 -0
  207. data/templates/cli/utility/database/mongodb +18 -0
  208. data/templates/cli/utility/database/mysql +21 -0
  209. data/templates/cli/utility/database/postgresql +17 -0
  210. data/templates/cli/utility/database/redis +16 -0
  211. data/templates/cli/utility/database/riak +11 -0
  212. data/templates/cli/utility/encryptor/gpg +12 -0
  213. data/templates/cli/utility/encryptor/openssl +9 -0
  214. data/templates/cli/utility/model.erb +23 -0
  215. data/templates/cli/utility/notifier/campfire +12 -0
  216. data/templates/cli/utility/notifier/hipchat +15 -0
  217. data/templates/cli/utility/notifier/mail +22 -0
  218. data/templates/cli/utility/notifier/presently +13 -0
  219. data/templates/cli/utility/notifier/prowl +11 -0
  220. data/templates/cli/utility/notifier/twitter +13 -0
  221. data/templates/cli/utility/splitter +7 -0
  222. data/templates/cli/utility/storage/cloud_files +22 -0
  223. data/templates/cli/utility/storage/dropbox +20 -0
  224. data/templates/cli/utility/storage/ftp +12 -0
  225. data/templates/cli/utility/storage/local +7 -0
  226. data/templates/cli/utility/storage/ninefold +9 -0
  227. data/templates/cli/utility/storage/rsync +11 -0
  228. data/templates/cli/utility/storage/s3 +19 -0
  229. data/templates/cli/utility/storage/scp +11 -0
  230. data/templates/cli/utility/storage/sftp +11 -0
  231. data/templates/cli/utility/syncer/cloud_files +48 -0
  232. data/templates/cli/utility/syncer/rsync_local +12 -0
  233. data/templates/cli/utility/syncer/rsync_pull +17 -0
  234. data/templates/cli/utility/syncer/rsync_push +17 -0
  235. data/templates/cli/utility/syncer/s3 +45 -0
  236. data/templates/general/links +11 -0
  237. data/templates/general/version.erb +2 -0
  238. data/templates/notifier/mail/failure.erb +9 -0
  239. data/templates/notifier/mail/success.erb +7 -0
  240. data/templates/notifier/mail/warning.erb +9 -0
  241. data/templates/storage/dropbox/authorization_url.erb +6 -0
  242. data/templates/storage/dropbox/authorized.erb +4 -0
  243. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  244. metadata +311 -0
@@ -0,0 +1,235 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Storage::Local do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:storage_path) do
8
+ File.join(File.expand_path(ENV['HOME'] || ''), 'backups')
9
+ end
10
+ let(:storage) do
11
+ Backup::Storage::Local.new(model) do |local|
12
+ local.keep = 5
13
+ end
14
+ end
15
+
16
+ describe '#initialize' do
17
+ it 'should set the correct values' do
18
+ storage.path.should == storage_path
19
+
20
+ storage.storage_id.should be_nil
21
+ storage.keep.should == 5
22
+ end
23
+
24
+ it 'should set a storage_id if given' do
25
+ local = Backup::Storage::Local.new(model, 'my storage_id')
26
+ local.storage_id.should == 'my storage_id'
27
+ end
28
+
29
+ it 'should expand any path given' do
30
+ storage = Backup::Storage::Local.new(model) do |local|
31
+ local.path = 'my_backups/path'
32
+ end
33
+ storage.path.should == File.expand_path('my_backups/path')
34
+ end
35
+
36
+ context 'when setting configuration defaults' do
37
+ after { Backup::Configuration::Storage::Local.clear_defaults! }
38
+
39
+ it 'should use the configured defaults' do
40
+ Backup::Configuration::Storage::Local.defaults do |local|
41
+ local.path = 'some_path'
42
+ local.keep = 'some_keep'
43
+ end
44
+ storage = Backup::Storage::Local.new(model)
45
+ storage.path.should == File.expand_path('some_path')
46
+
47
+ storage.storage_id.should be_nil
48
+ storage.keep.should == 'some_keep'
49
+ end
50
+
51
+ it 'should override the configured defaults' do
52
+ Backup::Configuration::Storage::Local.defaults do |local|
53
+ local.path = 'old_path'
54
+ local.keep = 'old_keep'
55
+ end
56
+ storage = Backup::Storage::Local.new(model) do |local|
57
+ local.path = 'new_path'
58
+ local.keep = 'new_keep'
59
+ end
60
+
61
+ storage.path.should == File.expand_path('new_path')
62
+
63
+ storage.storage_id.should be_nil
64
+ storage.keep.should == 'new_keep'
65
+ end
66
+ end # context 'when setting configuration defaults'
67
+
68
+ end # describe '#initialize'
69
+
70
+ describe '#transfer!' do
71
+ let(:package) { mock }
72
+ let(:s) { sequence '' }
73
+
74
+ before do
75
+ storage.instance_variable_set(:@package, package)
76
+ storage.stubs(:storage_name).returns('Storage::Local')
77
+ storage.stubs(:local_path).returns('/local/path')
78
+ end
79
+
80
+ context 'when transfer_method is :mv' do
81
+ before { storage.stubs(:transfer_method).returns(:mv) }
82
+ it 'should move the package files to their destination' do
83
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
84
+ returns('remote/path')
85
+ FileUtils.expects(:mkdir_p).in_sequence(s).with('remote/path')
86
+
87
+ storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
88
+ multiple_yields(
89
+ ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
90
+ ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
91
+ )
92
+ # first yield
93
+ Backup::Logger.expects(:message).in_sequence(s).with(
94
+ "Storage::Local started transferring " +
95
+ "'2011.12.31.11.00.02.backup.tar.enc-aa'."
96
+ )
97
+ FileUtils.expects(:mv).in_sequence(s).with(
98
+ File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'),
99
+ File.join('remote/path', 'backup.tar.enc-aa')
100
+ )
101
+ # second yield
102
+ Backup::Logger.expects(:message).in_sequence(s).with(
103
+ "Storage::Local started transferring " +
104
+ "'2011.12.31.11.00.02.backup.tar.enc-ab'."
105
+ )
106
+ FileUtils.expects(:mv).in_sequence(s).with(
107
+ File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'),
108
+ File.join('remote/path', 'backup.tar.enc-ab')
109
+ )
110
+
111
+ storage.send(:transfer!)
112
+ end
113
+ end # context 'when transfer_method is :mv'
114
+
115
+ context 'when transfer_method is :cp' do
116
+ before { storage.stubs(:transfer_method).returns(:cp) }
117
+ it 'should copy the package files to their destination' do
118
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
119
+ returns('remote/path')
120
+ FileUtils.expects(:mkdir_p).in_sequence(s).with('remote/path')
121
+
122
+ storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
123
+ multiple_yields(
124
+ ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
125
+ ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
126
+ )
127
+ # first yield
128
+ Backup::Logger.expects(:message).in_sequence(s).with(
129
+ "Storage::Local started transferring " +
130
+ "'2011.12.31.11.00.02.backup.tar.enc-aa'."
131
+ )
132
+ FileUtils.expects(:cp).in_sequence(s).with(
133
+ File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'),
134
+ File.join('remote/path', 'backup.tar.enc-aa')
135
+ )
136
+ # second yield
137
+ Backup::Logger.expects(:message).in_sequence(s).with(
138
+ "Storage::Local started transferring " +
139
+ "'2011.12.31.11.00.02.backup.tar.enc-ab'."
140
+ )
141
+ FileUtils.expects(:cp).in_sequence(s).with(
142
+ File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'),
143
+ File.join('remote/path', 'backup.tar.enc-ab')
144
+ )
145
+
146
+ storage.send(:transfer!)
147
+ end
148
+ end # context 'when transfer_method is :cp'
149
+
150
+ end # describe '#transfer!'
151
+
152
+ describe '#remove!' do
153
+ let(:package) { mock }
154
+ let(:s) { sequence '' }
155
+
156
+ before do
157
+ storage.stubs(:storage_name).returns('Storage::Local')
158
+ end
159
+
160
+ it 'should remove the package files' do
161
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
162
+ returns('remote/path')
163
+
164
+ storage.expects(:transferred_files_for).in_sequence(s).with(package).
165
+ multiple_yields(
166
+ ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
167
+ ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
168
+ )
169
+ # after both yields
170
+ Backup::Logger.expects(:message).in_sequence(s).with(
171
+ "Storage::Local started removing " +
172
+ "'2011.12.31.11.00.02.backup.tar.enc-aa'.\n" +
173
+ "Storage::Local started removing " +
174
+ "'2011.12.31.11.00.02.backup.tar.enc-ab'."
175
+ )
176
+ FileUtils.expects(:rm_r).in_sequence(s).with('remote/path')
177
+
178
+ storage.send(:remove!, package)
179
+ end
180
+ end # describe '#remove!'
181
+
182
+ describe '#transfer_method' do
183
+ context 'when the storage is the last for the model' do
184
+ before do
185
+ model.storages << storage
186
+ end
187
+
188
+ it 'should return :mv' do
189
+ storage.send(:transfer_method).should == :mv
190
+ storage.instance_variable_get(:@transfer_method).should == :mv
191
+ end
192
+
193
+ it 'should only check once' do
194
+ storage.instance_variable_set(:@transfer_method, :mv)
195
+ model.expects(:storages).never
196
+ storage.send(:transfer_method).should == :mv
197
+ end
198
+ end # context 'when the storage is the last for the model'
199
+
200
+ context 'when the storage is not the last for the model' do
201
+ let(:package) { mock }
202
+
203
+ before do
204
+ model.storages << storage
205
+ model.storages << Backup::Storage::Local.new(model)
206
+
207
+ storage.instance_variable_set(:@package, package)
208
+ end
209
+
210
+ it 'should log a warning and return :cp' do
211
+ storage.expects(:remote_path_for).with(package).returns('remote_path')
212
+ Backup::Logger.expects(:warn).with do |err|
213
+ err.should be_an_instance_of Backup::Errors::Storage::Local::TransferError
214
+ err.message.should ==
215
+ "Storage::Local::TransferError: Local File Copy Warning!\n" +
216
+ " The final backup file(s) for 'test label' (test_trigger)\n" +
217
+ " will be *copied* to 'remote_path'\n" +
218
+ " To avoid this, when using more than one Storage, the 'Local' Storage\n" +
219
+ " should be added *last* so the files may be *moved* to their destination."
220
+ end
221
+
222
+ storage.send(:transfer_method).should == :cp
223
+ storage.instance_variable_get(:@transfer_method).should == :cp
224
+ end
225
+
226
+ it 'should only check once' do
227
+ storage.instance_variable_set(:@transfer_method, :cp)
228
+ model.expects(:storages).never
229
+ storage.send(:transfer_method).should == :cp
230
+ end
231
+ end # context 'when the storage is not the last for the model'
232
+
233
+ end # describe '#transfer_method'
234
+
235
+ end
@@ -0,0 +1,319 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Storage::Ninefold do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:storage) do
8
+ Backup::Storage::Ninefold.new(model) do |nf|
9
+ nf.storage_token = 'my_token'
10
+ nf.storage_secret = 'my_secret'
11
+ nf.keep = 5
12
+ end
13
+ end
14
+
15
+ describe '#initialize' do
16
+ it 'should set the correct values' do
17
+ storage.storage_token.should == 'my_token'
18
+ storage.storage_secret.should == 'my_secret'
19
+ storage.path.should == 'backups'
20
+
21
+ storage.storage_id.should be_nil
22
+ storage.keep.should == 5
23
+ end
24
+
25
+ it 'should set a storage_id if given' do
26
+ nf = Backup::Storage::Ninefold.new(model, 'my storage_id')
27
+ nf.storage_id.should == 'my storage_id'
28
+ end
29
+
30
+ context 'when setting configuration defaults' do
31
+ after { Backup::Configuration::Storage::Ninefold.clear_defaults! }
32
+
33
+ it 'should use the configured defaults' do
34
+ Backup::Configuration::Storage::Ninefold.defaults do |nf|
35
+ nf.storage_token = 'some_token'
36
+ nf.storage_secret = 'some_secret'
37
+ nf.path = 'some_path'
38
+ nf.keep = 15
39
+ end
40
+ storage = Backup::Storage::Ninefold.new(model)
41
+ storage.storage_token.should == 'some_token'
42
+ storage.storage_secret.should == 'some_secret'
43
+ storage.path.should == 'some_path'
44
+
45
+ storage.storage_id.should be_nil
46
+ storage.keep.should == 15
47
+ end
48
+
49
+ it 'should override the configured defaults' do
50
+ Backup::Configuration::Storage::Ninefold.defaults do |nf|
51
+ nf.storage_token = 'old_token'
52
+ nf.storage_secret = 'old_secret'
53
+ nf.path = 'old_path'
54
+ nf.keep = 15
55
+ end
56
+ storage = Backup::Storage::Ninefold.new(model) do |nf|
57
+ nf.storage_token = 'new_token'
58
+ nf.storage_secret = 'new_secret'
59
+ nf.path = 'new_path'
60
+ nf.keep = 10
61
+ end
62
+
63
+ storage.storage_token.should == 'new_token'
64
+ storage.storage_secret.should == 'new_secret'
65
+ storage.path.should == 'new_path'
66
+
67
+ storage.storage_id.should be_nil
68
+ storage.keep.should == 10
69
+ end
70
+ end # context 'when setting configuration defaults'
71
+
72
+ end # describe '#initialize'
73
+
74
+ describe '#provider' do
75
+ it 'should set the Fog provider' do
76
+ storage.send(:provider).should == 'Ninefold'
77
+ end
78
+ end
79
+
80
+ describe '#connection' do
81
+ let(:connection) { mock }
82
+
83
+ it 'should create a new connection' do
84
+ Fog::Storage.expects(:new).once.with(
85
+ :provider => 'Ninefold',
86
+ :ninefold_storage_token => 'my_token',
87
+ :ninefold_storage_secret => 'my_secret'
88
+ ).returns(connection)
89
+ storage.send(:connection).should == connection
90
+ end
91
+
92
+ it 'should return an existing connection' do
93
+ Fog::Storage.expects(:new).once.returns(connection)
94
+ storage.send(:connection).should == connection
95
+ storage.send(:connection).should == connection
96
+ end
97
+ end # describe '#connection'
98
+
99
+ describe '#directory_for' do
100
+ let(:connection) { mock }
101
+ let(:directories) { mock }
102
+ let(:directory) { mock }
103
+
104
+ before do
105
+ storage.stubs(:connection).returns(connection)
106
+ connection.stubs(:directories).returns(directories)
107
+ end
108
+
109
+ context 'when the directory for the remote_path exists' do
110
+ it 'should return the directory' do
111
+ directories.expects(:get).with('remote_path').returns(directory)
112
+ storage.send(:directory_for, 'remote_path').should be(directory)
113
+ end
114
+ end
115
+
116
+ context 'when the directory for the remote_path does not exist' do
117
+ before do
118
+ directories.expects(:get).with('remote_path').returns(nil)
119
+ end
120
+
121
+ context 'when create is set to false' do
122
+ it 'should return nil' do
123
+ storage.send(:directory_for, 'remote_path').should be_nil
124
+ end
125
+ end
126
+
127
+ context 'when create is set to true' do
128
+ it 'should create and return the directory' do
129
+ directories.expects(:create).with(:key => 'remote_path').returns(directory)
130
+ storage.send(:directory_for, 'remote_path', true).should be(directory)
131
+ end
132
+ end
133
+ end
134
+ end # describe '#directory_for'
135
+
136
+ describe '#remote_path_for' do
137
+ let(:package) { mock }
138
+
139
+ before do
140
+ # for superclass method
141
+ package.expects(:trigger).returns('trigger')
142
+ package.expects(:time).returns('time')
143
+ end
144
+
145
+ it 'should remove any preceeding slash from the remote path' do
146
+ storage.path = '/backups'
147
+ storage.send(:remote_path_for, package).should == 'backups/trigger/time'
148
+ end
149
+ end
150
+
151
+ describe '#transfer!' do
152
+ let(:package) { mock }
153
+ let(:directory) { mock }
154
+ let(:directory_files) { mock }
155
+ let(:file) { mock }
156
+ let(:s) { sequence '' }
157
+
158
+ before do
159
+ storage.instance_variable_set(:@package, package)
160
+ storage.stubs(:storage_name).returns('Storage::Ninefold')
161
+ storage.stubs(:local_path).returns('/local/path')
162
+ directory.stubs(:files).returns(directory_files)
163
+ end
164
+
165
+ it 'should transfer the package files' do
166
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
167
+ returns('remote/path')
168
+ storage.expects(:directory_for).with('remote/path', true).returns(directory)
169
+
170
+ storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
171
+ multiple_yields(
172
+ ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
173
+ ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
174
+ )
175
+ # first yield
176
+ Backup::Logger.expects(:message).in_sequence(s).with(
177
+ "Storage::Ninefold started transferring " +
178
+ "'2011.12.31.11.00.02.backup.tar.enc-aa'."
179
+ )
180
+ File.expects(:open).in_sequence(s).with(
181
+ File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'), 'r'
182
+ ).yields(file)
183
+ directory_files.expects(:create).in_sequence(s).with(
184
+ :key => 'backup.tar.enc-aa', :body => file
185
+ )
186
+ # second yield
187
+ Backup::Logger.expects(:message).in_sequence(s).with(
188
+ "Storage::Ninefold started transferring " +
189
+ "'2011.12.31.11.00.02.backup.tar.enc-ab'."
190
+ )
191
+ File.expects(:open).in_sequence(s).with(
192
+ File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'), 'r'
193
+ ).yields(file)
194
+ directory_files.expects(:create).in_sequence(s).with(
195
+ :key => 'backup.tar.enc-ab', :body => file
196
+ )
197
+
198
+ storage.send(:transfer!)
199
+ end
200
+ end # describe '#transfer!'
201
+
202
+ describe '#remove!' do
203
+ let(:package) { mock }
204
+ let(:directory) { mock }
205
+ let(:directory_files) { mock }
206
+ let(:file) { mock }
207
+ let(:s) { sequence '' }
208
+
209
+ before do
210
+ storage.stubs(:storage_name).returns('Storage::Ninefold')
211
+ directory.stubs(:files).returns(directory_files)
212
+ end
213
+
214
+ it 'should remove the package files' do
215
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
216
+ returns('remote/path')
217
+ storage.expects(:directory_for).with('remote/path').returns(directory)
218
+
219
+ storage.expects(:transferred_files_for).in_sequence(s).with(package).
220
+ multiple_yields(
221
+ ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
222
+ ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
223
+ )
224
+ # first yield
225
+ Backup::Logger.expects(:message).in_sequence(s).with(
226
+ "Storage::Ninefold started removing " +
227
+ "'2011.12.31.11.00.02.backup.tar.enc-aa' from Ninefold."
228
+ )
229
+ directory_files.expects(:get).in_sequence(s).
230
+ with('backup.tar.enc-aa').returns(file)
231
+ file.expects(:destroy).in_sequence(s)
232
+ # second yield
233
+ Backup::Logger.expects(:message).in_sequence(s).with(
234
+ "Storage::Ninefold started removing " +
235
+ "'2011.12.31.11.00.02.backup.tar.enc-ab' from Ninefold."
236
+ )
237
+ directory_files.expects(:get).in_sequence(s).
238
+ with('backup.tar.enc-ab').returns(file)
239
+ file.expects(:destroy).in_sequence(s)
240
+
241
+ directory.expects(:destroy).in_sequence(s)
242
+
243
+ expect do
244
+ storage.send(:remove!, package)
245
+ end.not_to raise_error
246
+ end
247
+
248
+ context 'when the remote directory does not exist' do
249
+ it 'should raise an error' do
250
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
251
+ returns('remote/path')
252
+ storage.expects(:directory_for).with('remote/path').returns(nil)
253
+
254
+ storage.expects(:transferred_files_for).never
255
+ directory_files.expects(:get).never
256
+ file.expects(:destroy).never
257
+ directory.expects(:destroy).never
258
+
259
+ expect do
260
+ storage.send(:remove!, package)
261
+ end.to raise_error {|err|
262
+ err.should be_an_instance_of Backup::Errors::Storage::Ninefold::NotFoundError
263
+ err.message.should == 'Storage::Ninefold::NotFoundError: ' +
264
+ "Directory at 'remote/path' not found"
265
+ }
266
+ end
267
+ end
268
+
269
+ context 'when remote files do not exist' do
270
+ it 'should collect their names and raise an error after proceeding' do
271
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
272
+ returns('remote/path')
273
+ storage.expects(:directory_for).with('remote/path').returns(directory)
274
+
275
+ storage.expects(:transferred_files_for).in_sequence(s).with(package).
276
+ multiple_yields(
277
+ ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
278
+ ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab'],
279
+ ['2011.12.31.11.00.02.backup.tar.enc-ac', 'backup.tar.enc-ac']
280
+ )
281
+ # first yield (file not found)
282
+ Backup::Logger.expects(:message).in_sequence(s).with(
283
+ "Storage::Ninefold started removing " +
284
+ "'2011.12.31.11.00.02.backup.tar.enc-aa' from Ninefold."
285
+ )
286
+ directory_files.expects(:get).in_sequence(s).
287
+ with('backup.tar.enc-aa').returns(nil)
288
+ # second yield (file found and removed)
289
+ Backup::Logger.expects(:message).in_sequence(s).with(
290
+ "Storage::Ninefold started removing " +
291
+ "'2011.12.31.11.00.02.backup.tar.enc-ab' from Ninefold."
292
+ )
293
+ directory_files.expects(:get).in_sequence(s).
294
+ with('backup.tar.enc-ab').returns(file)
295
+ file.expects(:destroy).in_sequence(s)
296
+ # third yield (file not found)
297
+ Backup::Logger.expects(:message).in_sequence(s).with(
298
+ "Storage::Ninefold started removing " +
299
+ "'2011.12.31.11.00.02.backup.tar.enc-ac' from Ninefold."
300
+ )
301
+ directory_files.expects(:get).in_sequence(s).
302
+ with('backup.tar.enc-ac').returns(nil)
303
+
304
+ # directory removed
305
+ directory.expects(:destroy).in_sequence(s)
306
+
307
+ expect do
308
+ storage.send(:remove!, package)
309
+ end.to raise_error {|err|
310
+ err.should be_an_instance_of Backup::Errors::Storage::Ninefold::NotFoundError
311
+ err.message.should == 'Storage::Ninefold::NotFoundError: ' +
312
+ "The following file(s) were not found in 'remote/path'\n" +
313
+ " backup.tar.enc-aa\n backup.tar.enc-ac"
314
+ }
315
+ end
316
+ end
317
+ end # describe '#remove!'
318
+
319
+ end