backup_checksum 3.0.23

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of backup_checksum might be problematic. Click here for more details.

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,117 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Notifier::Prowl do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:notifier) do
8
+ Backup::Notifier::Prowl.new(model) do |prowl|
9
+ prowl.application = 'application'
10
+ prowl.api_key = 'api_key'
11
+ end
12
+ end
13
+
14
+ describe '#initialize' do
15
+ it 'should sets the correct values' do
16
+ notifier.application.should == 'application'
17
+ notifier.api_key.should == 'api_key'
18
+
19
+ notifier.on_success.should == true
20
+ notifier.on_warning.should == true
21
+ notifier.on_failure.should == true
22
+ end
23
+
24
+ context 'when using configuration defaults' do
25
+ after { Backup::Configuration::Notifier::Prowl.clear_defaults! }
26
+
27
+ it 'should use the configuration defaults' do
28
+ Backup::Configuration::Notifier::Prowl.defaults do |prowl|
29
+ prowl.application = 'default_app'
30
+ prowl.api_key = 'default_api_key'
31
+
32
+ prowl.on_success = false
33
+ prowl.on_warning = false
34
+ prowl.on_failure = false
35
+ end
36
+ notifier = Backup::Notifier::Prowl.new(model)
37
+ notifier.application.should == 'default_app'
38
+ notifier.api_key.should == 'default_api_key'
39
+
40
+ notifier.on_success.should == false
41
+ notifier.on_warning.should == false
42
+ notifier.on_failure.should == false
43
+ end
44
+
45
+ it 'should override the configuration defaults' do
46
+ Backup::Configuration::Notifier::Prowl.defaults do |prowl|
47
+ prowl.application = 'old_app'
48
+ prowl.api_key = 'old_api_key'
49
+
50
+ prowl.on_success = true
51
+ prowl.on_warning = false
52
+ prowl.on_failure = false
53
+ end
54
+ notifier = Backup::Notifier::Prowl.new(model) do |prowl|
55
+ prowl.application = 'new_app'
56
+ prowl.api_key = 'new_api_key'
57
+
58
+ prowl.on_success = false
59
+ prowl.on_warning = true
60
+ prowl.on_failure = true
61
+ end
62
+
63
+ notifier.application.should == 'new_app'
64
+ notifier.api_key.should == 'new_api_key'
65
+
66
+ notifier.on_success.should == false
67
+ notifier.on_warning.should == true
68
+ notifier.on_failure.should == true
69
+ end
70
+ end # context 'when using configuration defaults'
71
+ end
72
+
73
+ describe '#notify!' do
74
+ context 'when status is :success' do
75
+ it 'should send Success message' do
76
+ notifier.expects(:send_message).with(
77
+ '[Backup::Success]'
78
+ )
79
+ notifier.send(:notify!, :success)
80
+ end
81
+ end
82
+
83
+ context 'when status is :warning' do
84
+ it 'should send Warning message' do
85
+ notifier.expects(:send_message).with(
86
+ '[Backup::Warning]'
87
+ )
88
+ notifier.send(:notify!, :warning)
89
+ end
90
+ end
91
+
92
+ context 'when status is :failure' do
93
+ it 'should send Failure message' do
94
+ notifier.expects(:send_message).with(
95
+ '[Backup::Failure]'
96
+ )
97
+ notifier.send(:notify!, :failure)
98
+ end
99
+ end
100
+ end # describe '#notify!'
101
+
102
+ describe '#send_message' do
103
+ it 'should send the given message' do
104
+ client = mock
105
+ Prowler.expects(:new).with(
106
+ :application => 'application', :api_key => 'api_key'
107
+ ).returns(client)
108
+ client.expects(:notify).with(
109
+ 'a message',
110
+ 'test label (test_trigger)'
111
+ )
112
+
113
+ notifier.send(:send_message, 'a message')
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,132 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Notifier::Twitter do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:notifier) do
8
+ Backup::Notifier::Twitter.new(model) do |twitter|
9
+ twitter.consumer_key = 'consumer_key'
10
+ twitter.consumer_secret = 'consumer_secret'
11
+ twitter.oauth_token = 'oauth_token'
12
+ twitter.oauth_token_secret = 'oauth_token_secret'
13
+ end
14
+ end
15
+
16
+ describe '#initialize' do
17
+ it 'should sets the correct values' do
18
+ notifier.consumer_key.should == 'consumer_key'
19
+ notifier.consumer_secret.should == 'consumer_secret'
20
+ notifier.oauth_token.should == 'oauth_token'
21
+ notifier.oauth_token_secret.should == 'oauth_token_secret'
22
+
23
+ notifier.on_success.should == true
24
+ notifier.on_warning.should == true
25
+ notifier.on_failure.should == true
26
+ end
27
+
28
+ context 'when using configuration defaults' do
29
+ after { Backup::Configuration::Notifier::Twitter.clear_defaults! }
30
+
31
+ it 'should use the configuration defaults' do
32
+ Backup::Configuration::Notifier::Twitter.defaults do |twitter|
33
+ twitter.consumer_key = 'some_consumer_key'
34
+ twitter.consumer_secret = 'some_consumer_secret'
35
+ twitter.oauth_token = 'some_oauth_token'
36
+ twitter.oauth_token_secret = 'some_oauth_token_secret'
37
+
38
+ twitter.on_success = false
39
+ twitter.on_warning = false
40
+ twitter.on_failure = false
41
+ end
42
+ notifier = Backup::Notifier::Twitter.new(model)
43
+ notifier.consumer_key.should == 'some_consumer_key'
44
+ notifier.consumer_secret.should == 'some_consumer_secret'
45
+ notifier.oauth_token.should == 'some_oauth_token'
46
+ notifier.oauth_token_secret.should == 'some_oauth_token_secret'
47
+
48
+ notifier.on_success.should == false
49
+ notifier.on_warning.should == false
50
+ notifier.on_failure.should == false
51
+ end
52
+
53
+ it 'should override the configuration defaults' do
54
+ Backup::Configuration::Notifier::Twitter.defaults do |twitter|
55
+ twitter.consumer_key = 'old_consumer_key'
56
+ twitter.consumer_secret = 'old_consumer_secret'
57
+ twitter.oauth_token = 'old_oauth_token'
58
+ twitter.oauth_token_secret = 'old_oauth_token_secret'
59
+
60
+ twitter.on_success = true
61
+ twitter.on_warning = false
62
+ twitter.on_failure = false
63
+ end
64
+ notifier = Backup::Notifier::Twitter.new(model) do |twitter|
65
+ twitter.consumer_key = 'new_consumer_key'
66
+ twitter.consumer_secret = 'new_consumer_secret'
67
+ twitter.oauth_token = 'new_oauth_token'
68
+ twitter.oauth_token_secret = 'new_oauth_token_secret'
69
+
70
+ twitter.on_success = false
71
+ twitter.on_warning = true
72
+ twitter.on_failure = true
73
+ end
74
+
75
+ notifier.consumer_key.should == 'new_consumer_key'
76
+ notifier.consumer_secret.should == 'new_consumer_secret'
77
+ notifier.oauth_token.should == 'new_oauth_token'
78
+ notifier.oauth_token_secret.should == 'new_oauth_token_secret'
79
+
80
+ notifier.on_success.should == false
81
+ notifier.on_warning.should == true
82
+ notifier.on_failure.should == true
83
+ end
84
+ end # context 'when using configuration defaults'
85
+ end
86
+
87
+ describe '#notify!' do
88
+ context 'when status is :success' do
89
+ it 'should send Success message' do
90
+ notifier.expects(:send_message).with(
91
+ "[Backup::Success] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
92
+ )
93
+ notifier.send(:notify!, :success)
94
+ end
95
+ end
96
+
97
+ context 'when status is :warning' do
98
+ it 'should send Warning message' do
99
+ notifier.expects(:send_message).with(
100
+ "[Backup::Warning] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
101
+ )
102
+ notifier.send(:notify!, :warning)
103
+ end
104
+ end
105
+
106
+ context 'when status is :failure' do
107
+ it 'should send Failure message' do
108
+ notifier.expects(:send_message).with(
109
+ "[Backup::Failure] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
110
+ )
111
+ notifier.send(:notify!, :failure)
112
+ end
113
+ end
114
+ end # describe '#notify!'
115
+
116
+ describe '#send_message' do
117
+ it 'should send a message' do
118
+ client, config = mock, mock
119
+
120
+ ::Twitter.expects(:configure).yields(config)
121
+ config.expects(:consumer_key=).with('consumer_key')
122
+ config.expects(:consumer_secret=).with('consumer_secret')
123
+ config.expects(:oauth_token=).with('oauth_token')
124
+ config.expects(:oauth_token_secret=).with('oauth_token_secret')
125
+
126
+ ::Twitter::Client.expects(:new).returns(client)
127
+ client.expects(:update).with('a message')
128
+
129
+ notifier.send(:send_message, 'a message')
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Package do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:package) { Backup::Package.new(model) }
8
+
9
+ before do
10
+ model.instance_variable_set(:@time, 'model_time')
11
+ end
12
+
13
+ describe '#initialize' do
14
+ it 'should set all variables' do
15
+ package.time.should == 'model_time'
16
+ package.trigger.should == 'test_trigger'
17
+ package.extension.should == 'tar'
18
+ package.chunk_suffixes.should == []
19
+ package.version.should == Backup::Version.current
20
+ end
21
+ end
22
+
23
+ describe '#filenames' do
24
+ context 'when the package files were not split' do
25
+ it 'should return an array with the single package filename' do
26
+ package.filenames.should == ['model_time.test_trigger.tar']
27
+ end
28
+
29
+ it 'should reflect changes in the extension' do
30
+ package.extension << '.enc'
31
+ package.filenames.should == ['model_time.test_trigger.tar.enc']
32
+ end
33
+ end
34
+
35
+ context 'when the package files were split' do
36
+ before { package.chunk_suffixes = ['aa', 'ab'] }
37
+ it 'should return an array of the package filenames' do
38
+ package.filenames.should == ['model_time.test_trigger.tar-aa',
39
+ 'model_time.test_trigger.tar-ab']
40
+ end
41
+
42
+ it 'should reflect changes in the extension' do
43
+ package.extension << '.enc'
44
+ package.filenames.should == ['model_time.test_trigger.tar.enc-aa',
45
+ 'model_time.test_trigger.tar.enc-ab']
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#basename' do
51
+ it 'should return the base filename for the package' do
52
+ package.basename.should == 'model_time.test_trigger.tar'
53
+ end
54
+
55
+ it 'should reflect changes in the extension' do
56
+ package.extension << '.enc'
57
+ package.basename.should == 'model_time.test_trigger.tar.enc'
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,225 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../spec_helper.rb', __FILE__)
4
+
5
+ describe 'Backup::Packager' do
6
+ let(:packager) { Backup::Packager }
7
+
8
+ describe '#package!' do
9
+ let(:model) { mock }
10
+ let(:package) { mock }
11
+ let(:encryptor) { mock }
12
+ let(:splitter) { mock }
13
+ let(:checksum_creator) { mock }
14
+ let(:pipeline) { mock }
15
+ let(:procedure) { mock }
16
+ let(:s) { sequence '' }
17
+
18
+ context 'when pipeline command is successful' do
19
+ it 'should setup variables and perform packaging procedures' do
20
+ model.expects(:package).in_sequence(s).returns(package)
21
+ model.expects(:encryptor).in_sequence(s).returns(encryptor)
22
+ model.expects(:splitter).in_sequence(s).returns(splitter)
23
+ model.expects(:checksum_creator).in_sequence(s).returns(checksum_creator)
24
+ Backup::Pipeline.expects(:new).in_sequence(s).returns(pipeline)
25
+
26
+ Backup::Logger.expects(:message).in_sequence(s).with(
27
+ 'Packaging the backup files...'
28
+ )
29
+ packager.expects(:procedure).in_sequence(s).returns(procedure)
30
+ procedure.expects(:call).in_sequence(s)
31
+
32
+ pipeline.expects(:success?).in_sequence(s).returns(true)
33
+ Backup::Logger.expects(:message).in_sequence(s).with(
34
+ 'Packaging Complete!'
35
+ )
36
+
37
+ packager.package!(model)
38
+
39
+ packager.instance_variable_get(:@package).should be(package)
40
+ packager.instance_variable_get(:@encryptor).should be(encryptor)
41
+ packager.instance_variable_get(:@splitter).should be(splitter)
42
+ packager.instance_variable_get(:@pipeline).should be(pipeline)
43
+ packager.instance_variable_get(:@checksum_creator).should be(checksum_creator)
44
+ end
45
+ end #context 'when pipeline command is successful'
46
+
47
+ context 'when pipeline command is not successful' do
48
+ it 'should raise an error' do
49
+ model.expects(:package).in_sequence(s).returns(package)
50
+ model.expects(:encryptor).in_sequence(s).returns(encryptor)
51
+ model.expects(:splitter).in_sequence(s).returns(splitter)
52
+ model.expects(:checksum_creator).in_sequence(s).returns(checksum_creator)
53
+ Backup::Pipeline.expects(:new).in_sequence(s).returns(pipeline)
54
+
55
+ Backup::Logger.expects(:message).in_sequence(s).with(
56
+ 'Packaging the backup files...'
57
+ )
58
+ packager.expects(:procedure).in_sequence(s).returns(procedure)
59
+ procedure.expects(:call).in_sequence(s)
60
+
61
+ pipeline.expects(:success?).in_sequence(s).returns(false)
62
+ pipeline.expects(:error_messages).in_sequence(s).returns('pipeline_errors')
63
+
64
+ expect do
65
+ packager.package!(model)
66
+ end.to raise_error(
67
+ Backup::Errors::Packager::PipelineError,
68
+ "Packager::PipelineError: Failed to Create Backup Package\n" +
69
+ " pipeline_errors"
70
+ )
71
+
72
+ packager.instance_variable_get(:@package).should be(package)
73
+ packager.instance_variable_get(:@encryptor).should be(encryptor)
74
+ packager.instance_variable_get(:@splitter).should be(splitter)
75
+ packager.instance_variable_get(:@pipeline).should be(pipeline)
76
+ packager.instance_variable_get(:@checksum_creator).should be(checksum_creator)
77
+ end
78
+ end #context 'when pipeline command is successful'
79
+ end # describe '#package!'
80
+
81
+ describe '#procedure' do
82
+
83
+ module Fake
84
+ def self.stack_trace
85
+ @stack ||= []
86
+ end
87
+ class Encryptor
88
+ def encrypt_with
89
+ Fake.stack_trace << :encryptor_before
90
+ yield 'encryption_command', '.enc'
91
+ Fake.stack_trace << :encryptor_after
92
+ end
93
+ end
94
+ class Splitter
95
+ def split_with
96
+ Fake.stack_trace << :splitter_before
97
+ yield 'splitter_command'
98
+ Fake.stack_trace << :splitter_after
99
+ end
100
+ end
101
+ class Package
102
+ attr_accessor :trigger, :extension
103
+ def basename
104
+ 'base_filename.' + extension
105
+ end
106
+ end
107
+ class Checksum
108
+ def checksum_with
109
+ end
110
+ end
111
+ end
112
+
113
+ let(:package) { Fake::Package.new }
114
+ let(:encryptor) { Fake::Encryptor.new }
115
+ let(:splitter) { Fake::Splitter.new }
116
+ let(:checksum_creator) { Fake::Checksum.new }
117
+ let(:pipeline) { mock }
118
+ let(:s) { sequence '' }
119
+
120
+ before do
121
+ Fake.stack_trace.clear
122
+ packager.expects(:utility).with(:tar).returns('tar')
123
+ packager.instance_variable_set(:@package, package)
124
+ packager.instance_variable_set(:@pipeline, pipeline)
125
+ package.trigger = 'model_trigger'
126
+ package.extension = 'tar'
127
+ end
128
+
129
+ context 'when no encryptor or splitter are defined' do
130
+ it 'should package the backup without encryption into a single file' do
131
+ packager.instance_variable_set(:@encryptor, nil)
132
+ packager.instance_variable_set(:@splitter, nil)
133
+ packager.instance_variable_set(:@checksum_creator, nil)
134
+
135
+ pipeline.expects(:<<).in_sequence(s).with(
136
+ "tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
137
+ )
138
+ pipeline.expects(:<<).in_sequence(s).with(
139
+ "cat > #{ File.join(Backup::Config.tmp_path, 'base_filename.tar') }"
140
+ )
141
+ pipeline.expects(:run).in_sequence(s)
142
+
143
+ packager.send(:procedure).call
144
+ end
145
+ end
146
+
147
+ context 'when only an encryptor is configured' do
148
+ it 'should package the backup with encryption' do
149
+ packager.instance_variable_set(:@encryptor, encryptor)
150
+ packager.instance_variable_set(:@splitter, nil)
151
+ packager.instance_variable_set(:@checksum_creator, nil)
152
+
153
+ pipeline.expects(:<<).in_sequence(s).with(
154
+ "tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
155
+ )
156
+ pipeline.expects(:<<).in_sequence(s).with('encryption_command')
157
+ pipeline.expects(:<<).in_sequence(s).with(
158
+ "cat > #{ File.join(Backup::Config.tmp_path, 'base_filename.tar.enc') }"
159
+ )
160
+ pipeline.expects(:run).in_sequence(s).with do
161
+ Fake.stack_trace << :command_executed
162
+ true
163
+ end
164
+
165
+ packager.send(:procedure).call
166
+
167
+ Fake.stack_trace.should == [
168
+ :encryptor_before, :command_executed, :encryptor_after
169
+ ]
170
+ end
171
+ end
172
+
173
+ context 'when only a splitter is configured' do
174
+ it 'should package the backup without encryption through the splitter' do
175
+ packager.instance_variable_set(:@encryptor, nil)
176
+ packager.instance_variable_set(:@splitter, splitter)
177
+
178
+ pipeline.expects(:<<).in_sequence(s).with(
179
+ "tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
180
+ )
181
+ pipeline.expects(:<<).in_sequence(s).with('splitter_command')
182
+
183
+ pipeline.expects(:run).in_sequence(s).with do
184
+ Fake.stack_trace << :command_executed
185
+ true
186
+ end
187
+
188
+ packager.send(:procedure).call
189
+
190
+ Fake.stack_trace.should == [
191
+ :splitter_before, :command_executed, :splitter_after
192
+ ]
193
+ end
194
+ end
195
+
196
+ context 'when both an encryptor and a splitter are configured' do
197
+ it 'should package the backup with encryption through the splitter' do
198
+ packager.instance_variable_set(:@encryptor, encryptor)
199
+ packager.instance_variable_set(:@splitter, splitter)
200
+
201
+ pipeline.expects(:<<).in_sequence(s).with(
202
+ "tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
203
+ )
204
+ pipeline.expects(:<<).in_sequence(s).with('encryption_command')
205
+ pipeline.expects(:<<).in_sequence(s).with('splitter_command')
206
+
207
+ pipeline.expects(:run).in_sequence(s).with do
208
+ Fake.stack_trace << :command_executed
209
+ true
210
+ end
211
+
212
+ packager.send(:procedure).call
213
+
214
+ Fake.stack_trace.should == [
215
+ :encryptor_before, :splitter_before,
216
+ :command_executed,
217
+ :splitter_after, :encryptor_after
218
+ ]
219
+ package.extension.should == 'tar.enc'
220
+ end
221
+ end
222
+
223
+ end # describe '#procedure'
224
+
225
+ end