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.

Files changed (190) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +10 -0
  3. data/Gemfile +28 -0
  4. data/Guardfile +23 -0
  5. data/LICENSE.md +24 -0
  6. data/README.md +478 -0
  7. data/backup.gemspec +32 -0
  8. data/bin/backup +11 -0
  9. data/lib/backup.rb +133 -0
  10. data/lib/backup/archive.rb +117 -0
  11. data/lib/backup/binder.rb +22 -0
  12. data/lib/backup/cleaner.rb +121 -0
  13. data/lib/backup/cli/helpers.rb +93 -0
  14. data/lib/backup/cli/utility.rb +255 -0
  15. data/lib/backup/compressor/base.rb +35 -0
  16. data/lib/backup/compressor/bzip2.rb +50 -0
  17. data/lib/backup/compressor/custom.rb +53 -0
  18. data/lib/backup/compressor/gzip.rb +50 -0
  19. data/lib/backup/compressor/lzma.rb +52 -0
  20. data/lib/backup/compressor/pbzip2.rb +59 -0
  21. data/lib/backup/config.rb +174 -0
  22. data/lib/backup/configuration.rb +33 -0
  23. data/lib/backup/configuration/helpers.rb +130 -0
  24. data/lib/backup/configuration/store.rb +24 -0
  25. data/lib/backup/database/base.rb +53 -0
  26. data/lib/backup/database/mongodb.rb +230 -0
  27. data/lib/backup/database/mysql.rb +160 -0
  28. data/lib/backup/database/postgresql.rb +144 -0
  29. data/lib/backup/database/redis.rb +136 -0
  30. data/lib/backup/database/riak.rb +67 -0
  31. data/lib/backup/dependency.rb +108 -0
  32. data/lib/backup/encryptor/base.rb +29 -0
  33. data/lib/backup/encryptor/gpg.rb +760 -0
  34. data/lib/backup/encryptor/open_ssl.rb +72 -0
  35. data/lib/backup/errors.rb +124 -0
  36. data/lib/backup/hooks.rb +68 -0
  37. data/lib/backup/logger.rb +152 -0
  38. data/lib/backup/model.rb +409 -0
  39. data/lib/backup/notifier/base.rb +81 -0
  40. data/lib/backup/notifier/campfire.rb +155 -0
  41. data/lib/backup/notifier/hipchat.rb +93 -0
  42. data/lib/backup/notifier/mail.rb +206 -0
  43. data/lib/backup/notifier/prowl.rb +65 -0
  44. data/lib/backup/notifier/pushover.rb +88 -0
  45. data/lib/backup/notifier/twitter.rb +70 -0
  46. data/lib/backup/package.rb +47 -0
  47. data/lib/backup/packager.rb +100 -0
  48. data/lib/backup/pipeline.rb +110 -0
  49. data/lib/backup/splitter.rb +75 -0
  50. data/lib/backup/storage/base.rb +99 -0
  51. data/lib/backup/storage/cloudfiles.rb +87 -0
  52. data/lib/backup/storage/cycler.rb +117 -0
  53. data/lib/backup/storage/dropbox.rb +178 -0
  54. data/lib/backup/storage/ftp.rb +119 -0
  55. data/lib/backup/storage/local.rb +82 -0
  56. data/lib/backup/storage/ninefold.rb +116 -0
  57. data/lib/backup/storage/rsync.rb +149 -0
  58. data/lib/backup/storage/s3.rb +94 -0
  59. data/lib/backup/storage/scp.rb +99 -0
  60. data/lib/backup/storage/sftp.rb +108 -0
  61. data/lib/backup/syncer/base.rb +46 -0
  62. data/lib/backup/syncer/cloud/base.rb +247 -0
  63. data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
  64. data/lib/backup/syncer/cloud/s3.rb +68 -0
  65. data/lib/backup/syncer/rsync/base.rb +49 -0
  66. data/lib/backup/syncer/rsync/local.rb +55 -0
  67. data/lib/backup/syncer/rsync/pull.rb +36 -0
  68. data/lib/backup/syncer/rsync/push.rb +116 -0
  69. data/lib/backup/template.rb +46 -0
  70. data/lib/backup/version.rb +43 -0
  71. data/spec-live/.gitignore +6 -0
  72. data/spec-live/README +7 -0
  73. data/spec-live/backups/config.rb +83 -0
  74. data/spec-live/backups/config.yml.template +46 -0
  75. data/spec-live/backups/models.rb +184 -0
  76. data/spec-live/compressor/custom_spec.rb +30 -0
  77. data/spec-live/compressor/gzip_spec.rb +30 -0
  78. data/spec-live/encryptor/gpg_keys.rb +239 -0
  79. data/spec-live/encryptor/gpg_spec.rb +287 -0
  80. data/spec-live/notifier/mail_spec.rb +121 -0
  81. data/spec-live/spec_helper.rb +151 -0
  82. data/spec-live/storage/dropbox_spec.rb +151 -0
  83. data/spec-live/storage/local_spec.rb +83 -0
  84. data/spec-live/storage/scp_spec.rb +193 -0
  85. data/spec-live/syncer/cloud/s3_spec.rb +124 -0
  86. data/spec/archive_spec.rb +335 -0
  87. data/spec/cleaner_spec.rb +312 -0
  88. data/spec/cli/helpers_spec.rb +301 -0
  89. data/spec/cli/utility_spec.rb +411 -0
  90. data/spec/compressor/base_spec.rb +52 -0
  91. data/spec/compressor/bzip2_spec.rb +217 -0
  92. data/spec/compressor/custom_spec.rb +106 -0
  93. data/spec/compressor/gzip_spec.rb +217 -0
  94. data/spec/compressor/lzma_spec.rb +123 -0
  95. data/spec/compressor/pbzip2_spec.rb +165 -0
  96. data/spec/config_spec.rb +321 -0
  97. data/spec/configuration/helpers_spec.rb +247 -0
  98. data/spec/configuration/store_spec.rb +39 -0
  99. data/spec/configuration_spec.rb +62 -0
  100. data/spec/database/base_spec.rb +63 -0
  101. data/spec/database/mongodb_spec.rb +510 -0
  102. data/spec/database/mysql_spec.rb +411 -0
  103. data/spec/database/postgresql_spec.rb +353 -0
  104. data/spec/database/redis_spec.rb +334 -0
  105. data/spec/database/riak_spec.rb +176 -0
  106. data/spec/dependency_spec.rb +51 -0
  107. data/spec/encryptor/base_spec.rb +40 -0
  108. data/spec/encryptor/gpg_spec.rb +909 -0
  109. data/spec/encryptor/open_ssl_spec.rb +148 -0
  110. data/spec/errors_spec.rb +306 -0
  111. data/spec/hooks_spec.rb +35 -0
  112. data/spec/logger_spec.rb +367 -0
  113. data/spec/model_spec.rb +694 -0
  114. data/spec/notifier/base_spec.rb +104 -0
  115. data/spec/notifier/campfire_spec.rb +217 -0
  116. data/spec/notifier/hipchat_spec.rb +211 -0
  117. data/spec/notifier/mail_spec.rb +316 -0
  118. data/spec/notifier/prowl_spec.rb +138 -0
  119. data/spec/notifier/pushover_spec.rb +123 -0
  120. data/spec/notifier/twitter_spec.rb +153 -0
  121. data/spec/package_spec.rb +61 -0
  122. data/spec/packager_spec.rb +213 -0
  123. data/spec/pipeline_spec.rb +259 -0
  124. data/spec/spec_helper.rb +60 -0
  125. data/spec/splitter_spec.rb +120 -0
  126. data/spec/storage/base_spec.rb +166 -0
  127. data/spec/storage/cloudfiles_spec.rb +254 -0
  128. data/spec/storage/cycler_spec.rb +247 -0
  129. data/spec/storage/dropbox_spec.rb +480 -0
  130. data/spec/storage/ftp_spec.rb +271 -0
  131. data/spec/storage/local_spec.rb +259 -0
  132. data/spec/storage/ninefold_spec.rb +343 -0
  133. data/spec/storage/rsync_spec.rb +362 -0
  134. data/spec/storage/s3_spec.rb +245 -0
  135. data/spec/storage/scp_spec.rb +233 -0
  136. data/spec/storage/sftp_spec.rb +244 -0
  137. data/spec/syncer/base_spec.rb +109 -0
  138. data/spec/syncer/cloud/base_spec.rb +515 -0
  139. data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
  140. data/spec/syncer/cloud/s3_spec.rb +174 -0
  141. data/spec/syncer/rsync/base_spec.rb +98 -0
  142. data/spec/syncer/rsync/local_spec.rb +149 -0
  143. data/spec/syncer/rsync/pull_spec.rb +98 -0
  144. data/spec/syncer/rsync/push_spec.rb +333 -0
  145. data/spec/version_spec.rb +21 -0
  146. data/templates/cli/utility/archive +25 -0
  147. data/templates/cli/utility/compressor/bzip2 +4 -0
  148. data/templates/cli/utility/compressor/custom +11 -0
  149. data/templates/cli/utility/compressor/gzip +4 -0
  150. data/templates/cli/utility/compressor/lzma +10 -0
  151. data/templates/cli/utility/compressor/pbzip2 +10 -0
  152. data/templates/cli/utility/config +32 -0
  153. data/templates/cli/utility/database/mongodb +18 -0
  154. data/templates/cli/utility/database/mysql +21 -0
  155. data/templates/cli/utility/database/postgresql +17 -0
  156. data/templates/cli/utility/database/redis +16 -0
  157. data/templates/cli/utility/database/riak +11 -0
  158. data/templates/cli/utility/encryptor/gpg +27 -0
  159. data/templates/cli/utility/encryptor/openssl +9 -0
  160. data/templates/cli/utility/model.erb +23 -0
  161. data/templates/cli/utility/notifier/campfire +12 -0
  162. data/templates/cli/utility/notifier/hipchat +15 -0
  163. data/templates/cli/utility/notifier/mail +22 -0
  164. data/templates/cli/utility/notifier/prowl +11 -0
  165. data/templates/cli/utility/notifier/pushover +11 -0
  166. data/templates/cli/utility/notifier/twitter +13 -0
  167. data/templates/cli/utility/splitter +7 -0
  168. data/templates/cli/utility/storage/cloud_files +22 -0
  169. data/templates/cli/utility/storage/dropbox +20 -0
  170. data/templates/cli/utility/storage/ftp +12 -0
  171. data/templates/cli/utility/storage/local +7 -0
  172. data/templates/cli/utility/storage/ninefold +9 -0
  173. data/templates/cli/utility/storage/rsync +11 -0
  174. data/templates/cli/utility/storage/s3 +19 -0
  175. data/templates/cli/utility/storage/scp +11 -0
  176. data/templates/cli/utility/storage/sftp +11 -0
  177. data/templates/cli/utility/syncer/cloud_files +46 -0
  178. data/templates/cli/utility/syncer/rsync_local +12 -0
  179. data/templates/cli/utility/syncer/rsync_pull +17 -0
  180. data/templates/cli/utility/syncer/rsync_push +17 -0
  181. data/templates/cli/utility/syncer/s3 +43 -0
  182. data/templates/general/links +11 -0
  183. data/templates/general/version.erb +2 -0
  184. data/templates/notifier/mail/failure.erb +9 -0
  185. data/templates/notifier/mail/success.erb +7 -0
  186. data/templates/notifier/mail/warning.erb +9 -0
  187. data/templates/storage/dropbox/authorization_url.erb +6 -0
  188. data/templates/storage/dropbox/authorized.erb +4 -0
  189. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  190. metadata +277 -0
@@ -0,0 +1,123 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Notifier::Pushover do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:notifier) do
8
+ Backup::Notifier::Pushover.new(model) do |notifier|
9
+ notifier.user = 'user_token'
10
+ notifier.token = 'app_token'
11
+ notifier.title = 'title'
12
+ end
13
+ end
14
+
15
+ it 'should be a subclass of Notifier::Base' do
16
+ Backup::Notifier::Pushover.
17
+ superclass.should == Backup::Notifier::Base
18
+ end
19
+
20
+ describe '#initialize' do
21
+ after { Backup::Notifier::Pushover.clear_defaults! }
22
+
23
+ it 'should load pre-configured defaults through Base' do
24
+ Backup::Notifier::Pushover.any_instance.expects(:load_defaults!)
25
+ notifier
26
+ end
27
+
28
+ it 'should pass the model reference to Base' do
29
+ notifier.instance_variable_get(:@model).should == model
30
+ end
31
+
32
+ context 'when no pre-configured defaults have been set' do
33
+ it 'should use the values given' do
34
+ notifier.user.should == 'user_token'
35
+ notifier.token.should == 'app_token'
36
+ notifier.device.should be_nil
37
+ notifier.priority.should be_nil
38
+
39
+ notifier.on_success.should == true
40
+ notifier.on_warning.should == true
41
+ notifier.on_failure.should == true
42
+ end
43
+
44
+ it 'should use default values if none are given' do
45
+ notifier = Backup::Notifier::Pushover.new(model)
46
+ notifier.token.should be_nil
47
+ notifier.user.should be_nil
48
+ notifier.device.should be_nil
49
+ notifier.priority.should be_nil
50
+
51
+ notifier.on_success.should == true
52
+ notifier.on_warning.should == true
53
+ notifier.on_failure.should == true
54
+ end
55
+ end # context 'when no pre-configured defaults have been set'
56
+
57
+ context 'when pre-configured defaults have been set' do
58
+ before do
59
+ Backup::Notifier::Pushover.defaults do |n|
60
+ n.token = 'the_token'
61
+ n.user = 'the_user'
62
+ n.on_failure = false
63
+ end
64
+ end
65
+
66
+ it 'should use pre-configured defaults' do
67
+ notifier = Backup::Notifier::Pushover.new(model)
68
+
69
+ notifier.token.should == 'the_token'
70
+ notifier.user.should == 'the_user'
71
+
72
+ notifier.on_success.should == true
73
+ notifier.on_warning.should == true
74
+ notifier.on_failure.should == false
75
+ end
76
+
77
+ it 'should override pre-configured defaults' do
78
+ notifier = Backup::Notifier::Pushover.new(model) do |n|
79
+ n.token = 'new_token'
80
+ n.user = 'new_user'
81
+ n.on_success = false
82
+ n.on_failure = true
83
+ end
84
+
85
+ notifier.token.should == 'new_token'
86
+ notifier.user.should == 'new_user'
87
+
88
+ notifier.on_success.should == false
89
+ notifier.on_warning.should == true
90
+ notifier.on_failure.should == true
91
+ end
92
+ end # context 'when pre-configured defaults have been set'
93
+ end # describe '#initialize'
94
+
95
+ describe '#notify!' do
96
+ context 'when status is :success' do
97
+ it 'should send Success message' do
98
+ notifier.expects(:send_message).with(
99
+ '[Backup::Success] test label (test_trigger)'
100
+ )
101
+ notifier.send(:notify!, :success)
102
+ end
103
+ end
104
+
105
+ context 'when status is :warning' do
106
+ it 'should send Warning message' do
107
+ notifier.expects(:send_message).with(
108
+ '[Backup::Warning] test label (test_trigger)'
109
+ )
110
+ notifier.send(:notify!, :warning)
111
+ end
112
+ end
113
+
114
+ context 'when status is :failure' do
115
+ it 'should send Failure message' do
116
+ notifier.expects(:send_message).with(
117
+ '[Backup::Failure] test label (test_trigger)'
118
+ )
119
+ notifier.send(:notify!, :failure)
120
+ end
121
+ end
122
+ end # describe '#notify!'
123
+ end
@@ -0,0 +1,153 @@
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
+ it 'should be a subclass of Notifier::Base' do
17
+ Backup::Notifier::Twitter.
18
+ superclass.should == Backup::Notifier::Base
19
+ end
20
+
21
+ describe '#initialize' do
22
+ after { Backup::Notifier::Twitter.clear_defaults! }
23
+
24
+ it 'should load pre-configured defaults through Base' do
25
+ Backup::Notifier::Twitter.any_instance.expects(:load_defaults!)
26
+ notifier
27
+ end
28
+
29
+ it 'should pass the model reference to Base' do
30
+ notifier.instance_variable_get(:@model).should == model
31
+ end
32
+
33
+ context 'when no pre-configured defaults have been set' do
34
+ it 'should use the values given' do
35
+ notifier.consumer_key.should == 'consumer_key'
36
+ notifier.consumer_secret.should == 'consumer_secret'
37
+ notifier.oauth_token.should == 'oauth_token'
38
+ notifier.oauth_token_secret.should == 'oauth_token_secret'
39
+
40
+ notifier.on_success.should == true
41
+ notifier.on_warning.should == true
42
+ notifier.on_failure.should == true
43
+ end
44
+
45
+ it 'should use default values if none are given' do
46
+ notifier = Backup::Notifier::Twitter.new(model)
47
+ notifier.consumer_key.should be_nil
48
+ notifier.consumer_secret.should be_nil
49
+ notifier.oauth_token.should be_nil
50
+ notifier.oauth_token_secret.should be_nil
51
+
52
+ notifier.on_success.should == true
53
+ notifier.on_warning.should == true
54
+ notifier.on_failure.should == true
55
+ end
56
+ end # context 'when no pre-configured defaults have been set'
57
+
58
+ context 'when pre-configured defaults have been set' do
59
+ before do
60
+ Backup::Notifier::Twitter.defaults do |n|
61
+ n.consumer_key = 'some_consumer_key'
62
+ n.consumer_secret = 'some_consumer_secret'
63
+ n.oauth_token = 'some_oauth_token'
64
+ n.oauth_token_secret = 'some_oauth_token_secret'
65
+
66
+ n.on_success = false
67
+ n.on_warning = false
68
+ n.on_failure = false
69
+ end
70
+ end
71
+
72
+ it 'should use pre-configured defaults' do
73
+ notifier = Backup::Notifier::Twitter.new(model)
74
+ notifier.consumer_key.should == 'some_consumer_key'
75
+ notifier.consumer_secret.should == 'some_consumer_secret'
76
+ notifier.oauth_token.should == 'some_oauth_token'
77
+ notifier.oauth_token_secret.should == 'some_oauth_token_secret'
78
+
79
+ notifier.on_success.should == false
80
+ notifier.on_warning.should == false
81
+ notifier.on_failure.should == false
82
+ end
83
+
84
+ it 'should override pre-configured defaults' do
85
+ notifier = Backup::Notifier::Twitter.new(model) do |n|
86
+ n.consumer_key = 'new_consumer_key'
87
+ n.consumer_secret = 'new_consumer_secret'
88
+ n.oauth_token = 'new_oauth_token'
89
+ n.oauth_token_secret = 'new_oauth_token_secret'
90
+
91
+ n.on_success = false
92
+ n.on_warning = true
93
+ n.on_failure = true
94
+ end
95
+
96
+ notifier.consumer_key.should == 'new_consumer_key'
97
+ notifier.consumer_secret.should == 'new_consumer_secret'
98
+ notifier.oauth_token.should == 'new_oauth_token'
99
+ notifier.oauth_token_secret.should == 'new_oauth_token_secret'
100
+
101
+ notifier.on_success.should == false
102
+ notifier.on_warning.should == true
103
+ notifier.on_failure.should == true
104
+ end
105
+ end # context 'when pre-configured defaults have been set'
106
+ end # describe '#initialize'
107
+
108
+ describe '#notify!' do
109
+ context 'when status is :success' do
110
+ it 'should send Success message' do
111
+ notifier.expects(:send_message).with(
112
+ "[Backup::Success] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
113
+ )
114
+ notifier.send(:notify!, :success)
115
+ end
116
+ end
117
+
118
+ context 'when status is :warning' do
119
+ it 'should send Warning message' do
120
+ notifier.expects(:send_message).with(
121
+ "[Backup::Warning] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
122
+ )
123
+ notifier.send(:notify!, :warning)
124
+ end
125
+ end
126
+
127
+ context 'when status is :failure' do
128
+ it 'should send Failure message' do
129
+ notifier.expects(:send_message).with(
130
+ "[Backup::Failure] test label (test_trigger) (@ #{notifier.instance_variable_get("@model").time})"
131
+ )
132
+ notifier.send(:notify!, :failure)
133
+ end
134
+ end
135
+ end # describe '#notify!'
136
+
137
+ describe '#send_message' do
138
+ it 'should send a message' do
139
+ client, config = mock, mock
140
+
141
+ ::Twitter.expects(:configure).yields(config)
142
+ config.expects(:consumer_key=).with('consumer_key')
143
+ config.expects(:consumer_secret=).with('consumer_secret')
144
+ config.expects(:oauth_token=).with('oauth_token')
145
+ config.expects(:oauth_token_secret=).with('oauth_token_secret')
146
+
147
+ ::Twitter::Client.expects(:new).returns(client)
148
+ client.expects(:update).with('a message')
149
+
150
+ notifier.send(:send_message, 'a message')
151
+ end
152
+ end
153
+ 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,213 @@
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(:pipeline) { mock }
14
+ let(:procedure) { mock }
15
+ let(:s) { sequence '' }
16
+
17
+ context 'when pipeline command is successful' do
18
+ it 'should setup variables and perform packaging procedures' do
19
+ model.expects(:package).in_sequence(s).returns(package)
20
+ model.expects(:encryptor).in_sequence(s).returns(encryptor)
21
+ model.expects(:splitter).in_sequence(s).returns(splitter)
22
+ Backup::Pipeline.expects(:new).in_sequence(s).returns(pipeline)
23
+
24
+ Backup::Logger.expects(:message).in_sequence(s).with(
25
+ 'Packaging the backup files...'
26
+ )
27
+ packager.expects(:procedure).in_sequence(s).returns(procedure)
28
+ procedure.expects(:call).in_sequence(s)
29
+
30
+ pipeline.expects(:success?).in_sequence(s).returns(true)
31
+ Backup::Logger.expects(:message).in_sequence(s).with(
32
+ 'Packaging Complete!'
33
+ )
34
+
35
+ packager.package!(model)
36
+
37
+ packager.instance_variable_get(:@package).should be(package)
38
+ packager.instance_variable_get(:@encryptor).should be(encryptor)
39
+ packager.instance_variable_get(:@splitter).should be(splitter)
40
+ packager.instance_variable_get(:@pipeline).should be(pipeline)
41
+ end
42
+ end #context 'when pipeline command is successful'
43
+
44
+ context 'when pipeline command is not successful' do
45
+ it 'should raise an error' do
46
+ model.expects(:package).in_sequence(s).returns(package)
47
+ model.expects(:encryptor).in_sequence(s).returns(encryptor)
48
+ model.expects(:splitter).in_sequence(s).returns(splitter)
49
+ Backup::Pipeline.expects(:new).in_sequence(s).returns(pipeline)
50
+
51
+ Backup::Logger.expects(:message).in_sequence(s).with(
52
+ 'Packaging the backup files...'
53
+ )
54
+ packager.expects(:procedure).in_sequence(s).returns(procedure)
55
+ procedure.expects(:call).in_sequence(s)
56
+
57
+ pipeline.expects(:success?).in_sequence(s).returns(false)
58
+ pipeline.expects(:error_messages).in_sequence(s).returns('pipeline_errors')
59
+
60
+ expect do
61
+ packager.package!(model)
62
+ end.to raise_error(
63
+ Backup::Errors::Packager::PipelineError,
64
+ "Packager::PipelineError: Failed to Create Backup Package\n" +
65
+ " pipeline_errors"
66
+ )
67
+
68
+ packager.instance_variable_get(:@package).should be(package)
69
+ packager.instance_variable_get(:@encryptor).should be(encryptor)
70
+ packager.instance_variable_get(:@splitter).should be(splitter)
71
+ packager.instance_variable_get(:@pipeline).should be(pipeline)
72
+ end
73
+ end #context 'when pipeline command is successful'
74
+ end # describe '#package!'
75
+
76
+ describe '#procedure' do
77
+
78
+ module Fake
79
+ def self.stack_trace
80
+ @stack ||= []
81
+ end
82
+ class Encryptor
83
+ def encrypt_with
84
+ Fake.stack_trace << :encryptor_before
85
+ yield 'encryption_command', '.enc'
86
+ Fake.stack_trace << :encryptor_after
87
+ end
88
+ end
89
+ class Splitter
90
+ def split_with
91
+ Fake.stack_trace << :splitter_before
92
+ yield 'splitter_command'
93
+ Fake.stack_trace << :splitter_after
94
+ end
95
+ end
96
+ class Package
97
+ attr_accessor :trigger, :extension
98
+ def basename
99
+ 'base_filename.' + extension
100
+ end
101
+ end
102
+ end
103
+
104
+ let(:package) { Fake::Package.new }
105
+ let(:encryptor) { Fake::Encryptor.new }
106
+ let(:splitter) { Fake::Splitter.new }
107
+ let(:pipeline) { mock }
108
+ let(:s) { sequence '' }
109
+
110
+ before do
111
+ Fake.stack_trace.clear
112
+ packager.expects(:utility).with(:tar).returns('tar')
113
+ packager.instance_variable_set(:@package, package)
114
+ packager.instance_variable_set(:@pipeline, pipeline)
115
+ package.trigger = 'model_trigger'
116
+ package.extension = 'tar'
117
+ end
118
+
119
+ context 'when no encryptor or splitter are defined' do
120
+ it 'should package the backup without encryption into a single file' do
121
+ packager.instance_variable_set(:@encryptor, nil)
122
+ packager.instance_variable_set(:@splitter, nil)
123
+
124
+ pipeline.expects(:<<).in_sequence(s).with(
125
+ "tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
126
+ )
127
+ pipeline.expects(:<<).in_sequence(s).with(
128
+ "cat > #{ File.join(Backup::Config.tmp_path, 'base_filename.tar') }"
129
+ )
130
+ pipeline.expects(:run).in_sequence(s)
131
+
132
+ packager.send(:procedure).call
133
+ end
134
+ end
135
+
136
+ context 'when only an encryptor is configured' do
137
+ it 'should package the backup with encryption' do
138
+ packager.instance_variable_set(:@encryptor, encryptor)
139
+ packager.instance_variable_set(:@splitter, nil)
140
+
141
+ pipeline.expects(:<<).in_sequence(s).with(
142
+ "tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
143
+ )
144
+ pipeline.expects(:<<).in_sequence(s).with('encryption_command')
145
+ pipeline.expects(:<<).in_sequence(s).with(
146
+ "cat > #{ File.join(Backup::Config.tmp_path, 'base_filename.tar.enc') }"
147
+ )
148
+ pipeline.expects(:run).in_sequence(s).with do
149
+ Fake.stack_trace << :command_executed
150
+ true
151
+ end
152
+
153
+ packager.send(:procedure).call
154
+
155
+ Fake.stack_trace.should == [
156
+ :encryptor_before, :command_executed, :encryptor_after
157
+ ]
158
+ end
159
+ end
160
+
161
+ context 'when only a splitter is configured' do
162
+ it 'should package the backup without encryption through the splitter' do
163
+ packager.instance_variable_set(:@encryptor, nil)
164
+ packager.instance_variable_set(:@splitter, splitter)
165
+
166
+ pipeline.expects(:<<).in_sequence(s).with(
167
+ "tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
168
+ )
169
+ pipeline.expects(:<<).in_sequence(s).with('splitter_command')
170
+
171
+ pipeline.expects(:run).in_sequence(s).with do
172
+ Fake.stack_trace << :command_executed
173
+ true
174
+ end
175
+
176
+ packager.send(:procedure).call
177
+
178
+ Fake.stack_trace.should == [
179
+ :splitter_before, :command_executed, :splitter_after
180
+ ]
181
+ end
182
+ end
183
+
184
+ context 'when both an encryptor and a splitter are configured' do
185
+ it 'should package the backup with encryption through the splitter' do
186
+ packager.instance_variable_set(:@encryptor, encryptor)
187
+ packager.instance_variable_set(:@splitter, splitter)
188
+
189
+ pipeline.expects(:<<).in_sequence(s).with(
190
+ "tar -cf - -C '#{ Backup::Config.tmp_path }' 'model_trigger'"
191
+ )
192
+ pipeline.expects(:<<).in_sequence(s).with('encryption_command')
193
+ pipeline.expects(:<<).in_sequence(s).with('splitter_command')
194
+
195
+ pipeline.expects(:run).in_sequence(s).with do
196
+ Fake.stack_trace << :command_executed
197
+ true
198
+ end
199
+
200
+ packager.send(:procedure).call
201
+
202
+ Fake.stack_trace.should == [
203
+ :encryptor_before, :splitter_before,
204
+ :command_executed,
205
+ :splitter_after, :encryptor_after
206
+ ]
207
+ package.extension.should == 'tar.enc'
208
+ end
209
+ end
210
+
211
+ end # describe '#procedure'
212
+
213
+ end