backup 3.0.19 → 3.0.20
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.
- data/.gitignore +4 -0
- data/Gemfile +9 -8
- data/Gemfile.lock +19 -1
- data/Guardfile +13 -9
- data/README.md +93 -31
- data/backup.gemspec +3 -3
- data/bin/backup +6 -283
- data/lib/backup.rb +101 -72
- data/lib/backup/archive.rb +21 -9
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +36 -0
- data/lib/backup/cli/helpers.rb +103 -0
- data/lib/backup/cli/utility.rb +308 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/pbzip2.rb +76 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/riak.rb +25 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +6 -0
- data/lib/backup/configuration/helpers.rb +5 -18
- data/lib/backup/configuration/notifier/base.rb +13 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +38 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +4 -0
- data/lib/backup/configuration/storage/dropbox.rb +8 -4
- data/lib/backup/database/base.rb +10 -2
- data/lib/backup/database/mongodb.rb +16 -19
- data/lib/backup/database/mysql.rb +2 -2
- data/lib/backup/database/postgresql.rb +2 -2
- data/lib/backup/database/redis.rb +15 -7
- data/lib/backup/database/riak.rb +45 -0
- data/lib/backup/dependency.rb +21 -7
- data/lib/backup/encryptor/base.rb +1 -1
- data/lib/backup/encryptor/open_ssl.rb +20 -5
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/finder.rb +11 -3
- data/lib/backup/logger.rb +121 -82
- data/lib/backup/model.rb +103 -44
- data/lib/backup/notifier/base.rb +50 -0
- data/lib/backup/notifier/campfire.rb +32 -52
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +100 -61
- data/lib/backup/notifier/presently.rb +31 -40
- data/lib/backup/notifier/prowl.rb +73 -0
- data/lib/backup/notifier/twitter.rb +29 -39
- data/lib/backup/packager.rb +25 -0
- data/lib/backup/splitter.rb +62 -0
- data/lib/backup/storage/base.rb +178 -18
- data/lib/backup/storage/cloudfiles.rb +34 -28
- data/lib/backup/storage/dropbox.rb +64 -67
- data/lib/backup/storage/ftp.rb +48 -40
- data/lib/backup/storage/local.rb +33 -28
- data/lib/backup/storage/ninefold.rb +40 -26
- data/lib/backup/storage/object.rb +8 -6
- data/lib/backup/storage/rsync.rb +61 -51
- data/lib/backup/storage/s3.rb +29 -27
- data/lib/backup/storage/scp.rb +56 -36
- data/lib/backup/storage/sftp.rb +49 -33
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/rsync.rb +1 -1
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +34 -9
- data/spec/backup_spec.rb +1 -1
- data/spec/cli/helpers_spec.rb +35 -0
- data/spec/cli/utility_spec.rb +38 -0
- data/spec/compressor/bzip2_spec.rb +1 -1
- data/spec/compressor/gzip_spec.rb +1 -1
- data/spec/compressor/lzma_spec.rb +1 -1
- data/spec/compressor/pbzip2_spec.rb +63 -0
- data/spec/configuration/base_spec.rb +1 -1
- data/spec/configuration/compressor/bzip2_spec.rb +1 -1
- data/spec/configuration/compressor/gzip_spec.rb +1 -1
- data/spec/configuration/compressor/lzma_spec.rb +1 -1
- data/spec/configuration/database/base_spec.rb +1 -1
- data/spec/configuration/database/mongodb_spec.rb +1 -1
- data/spec/configuration/database/mysql_spec.rb +1 -1
- data/spec/configuration/database/postgresql_spec.rb +1 -1
- data/spec/configuration/database/redis_spec.rb +1 -1
- data/spec/configuration/database/riak_spec.rb +31 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -1
- data/spec/configuration/encryptor/open_ssl_spec.rb +4 -1
- data/spec/configuration/notifier/campfire_spec.rb +1 -1
- data/spec/configuration/notifier/hipchat_spec.rb +43 -0
- data/spec/configuration/notifier/mail_spec.rb +34 -22
- data/spec/configuration/notifier/presently_spec.rb +1 -1
- data/spec/configuration/notifier/prowl_spec.rb +28 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -1
- data/spec/configuration/storage/cloudfiles_spec.rb +19 -16
- data/spec/configuration/storage/dropbox_spec.rb +1 -1
- data/spec/configuration/storage/ftp_spec.rb +1 -1
- data/spec/configuration/storage/local_spec.rb +1 -1
- data/spec/configuration/storage/ninefold_spec.rb +1 -1
- data/spec/configuration/storage/rsync_spec.rb +1 -1
- data/spec/configuration/storage/s3_spec.rb +1 -1
- data/spec/configuration/storage/scp_spec.rb +1 -1
- data/spec/configuration/storage/sftp_spec.rb +1 -1
- data/spec/configuration/syncer/rsync_spec.rb +1 -1
- data/spec/configuration/syncer/s3_spec.rb +1 -1
- data/spec/database/base_spec.rb +10 -1
- data/spec/database/mongodb_spec.rb +34 -7
- data/spec/database/mysql_spec.rb +8 -7
- data/spec/database/postgresql_spec.rb +8 -7
- data/spec/database/redis_spec.rb +39 -9
- data/spec/database/riak_spec.rb +50 -0
- data/spec/encryptor/gpg_spec.rb +1 -1
- data/spec/encryptor/open_ssl_spec.rb +77 -20
- data/spec/errors_spec.rb +306 -0
- data/spec/finder_spec.rb +91 -0
- data/spec/logger_spec.rb +254 -33
- data/spec/model_spec.rb +120 -15
- data/spec/notifier/campfire_spec.rb +127 -52
- data/spec/notifier/hipchat_spec.rb +193 -0
- data/spec/notifier/mail_spec.rb +290 -74
- data/spec/notifier/presently_spec.rb +290 -73
- data/spec/notifier/prowl_spec.rb +149 -0
- data/spec/notifier/twitter_spec.rb +106 -41
- data/spec/spec_helper.rb +8 -2
- data/spec/splitter_spec.rb +71 -0
- data/spec/storage/base_spec.rb +280 -19
- data/spec/storage/cloudfiles_spec.rb +38 -22
- data/spec/storage/dropbox_spec.rb +17 -13
- data/spec/storage/ftp_spec.rb +145 -55
- data/spec/storage/local_spec.rb +6 -6
- data/spec/storage/ninefold_spec.rb +70 -29
- data/spec/storage/object_spec.rb +44 -44
- data/spec/storage/rsync_spec.rb +186 -63
- data/spec/storage/s3_spec.rb +23 -24
- data/spec/storage/scp_spec.rb +116 -41
- data/spec/storage/sftp_spec.rb +124 -46
- data/spec/syncer/rsync_spec.rb +3 -3
- data/spec/syncer/s3_spec.rb +1 -1
- data/spec/version_spec.rb +1 -1
- data/templates/cli/utility/archive +13 -0
- data/{lib/templates → templates/cli/utility}/compressor/bzip2 +1 -1
- data/{lib/templates → templates/cli/utility}/compressor/gzip +1 -1
- data/{lib/templates → templates/cli/utility}/compressor/lzma +0 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -0
- data/{lib/templates → templates/cli/utility}/database/mongodb +1 -1
- data/{lib/templates → templates/cli/utility}/database/mysql +1 -1
- data/{lib/templates → templates/cli/utility}/database/postgresql +1 -1
- data/{lib/templates → templates/cli/utility}/database/redis +1 -1
- data/templates/cli/utility/database/riak +8 -0
- data/{lib/templates → templates/cli/utility}/encryptor/gpg +1 -1
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/{lib/templates → templates/cli/utility}/notifier/campfire +2 -1
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/{lib/templates → templates/cli/utility}/notifier/mail +6 -1
- data/{lib/templates → templates/cli/utility}/notifier/presently +1 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/{lib/templates → templates/cli/utility}/notifier/twitter +2 -1
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloudfiles +12 -0
- data/{lib/templates → templates/cli/utility}/storage/dropbox +1 -1
- data/{lib/templates → templates/cli/utility}/storage/ftp +0 -0
- data/templates/cli/utility/storage/local +7 -0
- data/{lib/templates → templates/cli/utility}/storage/ninefold +1 -1
- data/templates/cli/utility/storage/rsync +11 -0
- data/{lib/templates → templates/cli/utility}/storage/s3 +0 -2
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/{lib/templates → templates/cli/utility}/syncer/rsync +1 -1
- data/{lib/templates → templates/cli/utility}/syncer/s3 +1 -1
- 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 +81 -45
- data/lib/backup/cli.rb +0 -110
- data/lib/backup/exception/command_failed.rb +0 -8
- data/lib/backup/exception/command_not_found.rb +0 -8
- data/lib/backup/notifier/binder.rb +0 -32
- data/lib/backup/notifier/templates/notify_failure.erb +0 -33
- data/lib/backup/notifier/templates/notify_success.erb +0 -16
- data/lib/templates/archive +0 -7
- data/lib/templates/encryptor/openssl +0 -8
- data/lib/templates/readme +0 -15
- data/lib/templates/storage/cloudfiles +0 -11
- data/lib/templates/storage/local +0 -7
- data/lib/templates/storage/rsync +0 -11
- data/lib/templates/storage/scp +0 -11
- data/lib/templates/storage/sftp +0 -11
|
@@ -1,99 +1,316 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
|
-
require File.
|
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
4
4
|
|
|
5
5
|
describe Backup::Notifier::Presently do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
|
|
7
|
+
describe '#initialize' do
|
|
8
|
+
let(:notifier) do
|
|
9
|
+
Backup::Notifier::Presently.new do |presently|
|
|
10
|
+
presently.user_name = 'user_name'
|
|
11
|
+
presently.subdomain = 'subdomain'
|
|
12
|
+
presently.password = 'password'
|
|
13
|
+
presently.group_id = 'group_id'
|
|
14
|
+
end
|
|
12
15
|
end
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
presently.on_failure = true
|
|
16
|
+
|
|
17
|
+
it 'sets the correct defaults' do
|
|
18
|
+
notifier.user_name.should == 'user_name'
|
|
19
|
+
notifier.subdomain.should == 'subdomain'
|
|
20
|
+
notifier.password.should == 'password'
|
|
21
|
+
notifier.group_id.should == 'group_id'
|
|
22
|
+
|
|
23
|
+
notifier.on_success.should == true
|
|
24
|
+
notifier.on_warning.should == true
|
|
25
|
+
notifier.on_failure.should == true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'uses and overrides configuration defaults' do
|
|
29
|
+
Backup::Configuration::Notifier::Presently.defaults do |notifier|
|
|
30
|
+
notifier.user_name = 'old_user_name'
|
|
31
|
+
notifier.on_success = false
|
|
32
|
+
notifier.on_failure = true
|
|
31
33
|
end
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
presently = Backup::Notifier::Presently.new do |notifier|
|
|
35
|
+
notifier.user_name = 'new_user_name'
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
presently.user_name.should == 'new_user_name'
|
|
39
|
+
presently.on_success.should == false
|
|
40
|
+
presently.on_warning.should == true
|
|
41
|
+
presently.on_failure.should == true
|
|
39
42
|
end
|
|
40
|
-
end
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
Backup::Notifier::Presently
|
|
45
|
-
|
|
44
|
+
it 'creates a Presently::Client (using HTTParty)' do
|
|
45
|
+
client = notifier.presently_client
|
|
46
|
+
client.should be_an_instance_of Backup::Notifier::Presently::Client
|
|
47
|
+
client.subdomain.should == notifier.subdomain
|
|
48
|
+
client.user_name.should == notifier.user_name
|
|
49
|
+
client.password.should == notifier.password
|
|
50
|
+
client.group_id.should == notifier.group_id
|
|
51
|
+
client.class.base_uri.
|
|
52
|
+
should == "https://#{notifier.subdomain}.presently.com"
|
|
53
|
+
client.class.default_options.should have_key(:basic_auth)
|
|
54
|
+
client.class.default_options[:basic_auth][:username].
|
|
55
|
+
should == notifier.user_name
|
|
56
|
+
client.class.default_options[:basic_auth][:password].
|
|
57
|
+
should == notifier.password
|
|
46
58
|
end
|
|
47
|
-
|
|
59
|
+
|
|
60
|
+
end # describe '#initialize'
|
|
48
61
|
|
|
49
62
|
describe '#perform!' do
|
|
50
|
-
let(:model) { Backup::Model.new('
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
63
|
+
let(:model) { Backup::Model.new('trigger', 'label') {} }
|
|
64
|
+
let(:post_uri) { '/api/twitter/statuses/update.json' }
|
|
65
|
+
let(:post_body) { { :status => nil, :source => 'Backup Notifier' } }
|
|
66
|
+
let(:message) { '[Backup::%s] label (trigger)' }
|
|
55
67
|
|
|
56
|
-
context
|
|
57
|
-
|
|
58
|
-
Backup::
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
context 'with group_id' do
|
|
69
|
+
let(:notifier) do
|
|
70
|
+
Backup::Notifier::Presently.new do |presently|
|
|
71
|
+
presently.user_name = 'user_name'
|
|
72
|
+
presently.subdomain = 'subdomain'
|
|
73
|
+
presently.password = 'password'
|
|
74
|
+
presently.group_id = 'group_id'
|
|
75
|
+
end
|
|
62
76
|
end
|
|
77
|
+
let(:client) { notifier.presently_client }
|
|
63
78
|
|
|
64
|
-
|
|
65
|
-
notifier.expects("notify_success!").never
|
|
79
|
+
before do
|
|
66
80
|
notifier.on_success = false
|
|
67
|
-
notifier.
|
|
81
|
+
notifier.on_warning = false
|
|
82
|
+
notifier.on_failure = false
|
|
68
83
|
end
|
|
69
|
-
end
|
|
70
84
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
context 'success' do
|
|
86
|
+
|
|
87
|
+
context 'when on_success is true' do
|
|
88
|
+
before { notifier.on_success = true }
|
|
89
|
+
|
|
90
|
+
it 'sends success message' do
|
|
91
|
+
notifier.expects(:log!)
|
|
92
|
+
status = message % 'Success'
|
|
93
|
+
client.class.expects(:post).with(
|
|
94
|
+
post_uri, :body => post_body.merge(
|
|
95
|
+
{ :status => "d @#{notifier.group_id} %s" % status }
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
notifier.perform!(model)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context 'when on_success is false' do
|
|
104
|
+
it 'sends no message' do
|
|
105
|
+
notifier.expects(:log!).never
|
|
106
|
+
notifier.expects(:notify!).never
|
|
107
|
+
client.expects(:update).never
|
|
108
|
+
|
|
109
|
+
notifier.perform!(model)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end # context 'success'
|
|
114
|
+
|
|
115
|
+
context 'warning' do
|
|
116
|
+
before { Backup::Logger.stubs(:has_warnings?).returns(true) }
|
|
117
|
+
|
|
118
|
+
context 'when on_success is true' do
|
|
119
|
+
before { notifier.on_success = true }
|
|
120
|
+
|
|
121
|
+
it 'sends warning message' do
|
|
122
|
+
notifier.expects(:log!)
|
|
123
|
+
status = message % 'Warning'
|
|
124
|
+
client.class.expects(:post).with(
|
|
125
|
+
post_uri, :body => post_body.merge(
|
|
126
|
+
{ :status => "d @#{notifier.group_id} %s" % status }
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
notifier.perform!(model)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
context 'when on_warning is true' do
|
|
135
|
+
before { notifier.on_warning = true }
|
|
136
|
+
|
|
137
|
+
it 'sends warning message' do
|
|
138
|
+
notifier.expects(:log!)
|
|
139
|
+
status = message % 'Warning'
|
|
140
|
+
client.class.expects(:post).with(
|
|
141
|
+
post_uri, :body => post_body.merge(
|
|
142
|
+
{ :status => "d @#{notifier.group_id} %s" % status }
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
notifier.perform!(model)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
context 'when on_success and on_warning are false' do
|
|
151
|
+
it 'sends no message' do
|
|
152
|
+
notifier.expects(:log!).never
|
|
153
|
+
notifier.expects(:notify!).never
|
|
154
|
+
client.expects(:update).never
|
|
155
|
+
|
|
156
|
+
notifier.perform!(model)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
end # context 'warning'
|
|
161
|
+
|
|
162
|
+
context 'failure' do
|
|
163
|
+
|
|
164
|
+
context 'when on_failure is true' do
|
|
165
|
+
before { notifier.on_failure = true }
|
|
166
|
+
|
|
167
|
+
it 'sends failure message' do
|
|
168
|
+
notifier.expects(:log!)
|
|
169
|
+
status = message % 'Failure'
|
|
170
|
+
client.class.expects(:post).with(
|
|
171
|
+
post_uri, :body => post_body.merge(
|
|
172
|
+
{ :status => "d @#{notifier.group_id} %s" % status }
|
|
173
|
+
)
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
notifier.perform!(model, Exception.new)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
context 'when on_failure is false' do
|
|
181
|
+
it 'sends no message' do
|
|
182
|
+
notifier.expects(:log!).never
|
|
183
|
+
notifier.expects(:notify!).never
|
|
184
|
+
client.expects(:update).never
|
|
185
|
+
|
|
186
|
+
notifier.perform!(model, Exception.new)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
end # context 'failure'
|
|
191
|
+
|
|
192
|
+
end # context 'with group_id'
|
|
193
|
+
|
|
194
|
+
context 'without group_id' do
|
|
195
|
+
let(:notifier) do
|
|
196
|
+
Backup::Notifier::Presently.new do |presently|
|
|
197
|
+
presently.user_name = 'user_name'
|
|
198
|
+
presently.subdomain = 'subdomain'
|
|
199
|
+
presently.password = 'password'
|
|
200
|
+
presently.group_id = nil
|
|
201
|
+
end
|
|
77
202
|
end
|
|
203
|
+
let(:client) { notifier.presently_client }
|
|
78
204
|
|
|
79
|
-
|
|
80
|
-
notifier.
|
|
205
|
+
before do
|
|
206
|
+
notifier.on_success = false
|
|
207
|
+
notifier.on_warning = false
|
|
81
208
|
notifier.on_failure = false
|
|
82
|
-
notifier.perform!(model, Exception.new)
|
|
83
209
|
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
210
|
|
|
87
|
-
|
|
88
|
-
let(:client) do
|
|
89
|
-
Backup::Notifier::Presently::Client.new('subdomain', 'user_name', 'password', 'group_id')
|
|
90
|
-
end
|
|
211
|
+
context 'success' do
|
|
91
212
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
213
|
+
context 'when on_success is true' do
|
|
214
|
+
before { notifier.on_success = true }
|
|
215
|
+
|
|
216
|
+
it 'sends success message' do
|
|
217
|
+
notifier.expects(:log!)
|
|
218
|
+
client.class.expects(:post).with(
|
|
219
|
+
post_uri, :body => post_body.merge(
|
|
220
|
+
{ :status => message % 'Success' }
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
notifier.perform!(model)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
context 'when on_success is false' do
|
|
229
|
+
it 'sends no message' do
|
|
230
|
+
notifier.expects(:log!).never
|
|
231
|
+
notifier.expects(:notify!).never
|
|
232
|
+
client.expects(:update).never
|
|
233
|
+
|
|
234
|
+
notifier.perform!(model)
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
end # context 'success'
|
|
239
|
+
|
|
240
|
+
context 'warning' do
|
|
241
|
+
before { Backup::Logger.stubs(:has_warnings?).returns(true) }
|
|
242
|
+
|
|
243
|
+
context 'when on_success is true' do
|
|
244
|
+
before { notifier.on_success = true }
|
|
245
|
+
|
|
246
|
+
it 'sends warning message' do
|
|
247
|
+
notifier.expects(:log!)
|
|
248
|
+
client.class.expects(:post).with(
|
|
249
|
+
post_uri, :body => post_body.merge(
|
|
250
|
+
{ :status => message % 'Warning' }
|
|
251
|
+
)
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
notifier.perform!(model)
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
context 'when on_warning is true' do
|
|
259
|
+
before { notifier.on_warning = true }
|
|
260
|
+
|
|
261
|
+
it 'sends warning message' do
|
|
262
|
+
notifier.expects(:log!)
|
|
263
|
+
client.class.expects(:post).with(
|
|
264
|
+
post_uri, :body => post_body.merge(
|
|
265
|
+
{ :status => message % 'Warning' }
|
|
266
|
+
)
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
notifier.perform!(model)
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
context 'when on_success and on_warning are false' do
|
|
274
|
+
it 'sends no message' do
|
|
275
|
+
notifier.expects(:log!).never
|
|
276
|
+
notifier.expects(:notify!).never
|
|
277
|
+
client.expects(:update).never
|
|
278
|
+
|
|
279
|
+
notifier.perform!(model)
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
end # context 'warning'
|
|
284
|
+
|
|
285
|
+
context 'failure' do
|
|
286
|
+
|
|
287
|
+
context 'when on_failure is true' do
|
|
288
|
+
before { notifier.on_failure = true }
|
|
289
|
+
|
|
290
|
+
it 'sends failure message' do
|
|
291
|
+
notifier.expects(:log!)
|
|
292
|
+
client.class.expects(:post).with(
|
|
293
|
+
post_uri, :body => post_body.merge(
|
|
294
|
+
{ :status => message % 'Failure' }
|
|
295
|
+
)
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
notifier.perform!(model, Exception.new)
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
context 'when on_failure is false' do
|
|
303
|
+
it 'sends no message' do
|
|
304
|
+
notifier.expects(:log!).never
|
|
305
|
+
notifier.expects(:notify!).never
|
|
306
|
+
client.expects(:update).never
|
|
307
|
+
|
|
308
|
+
notifier.perform!(model, Exception.new)
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
end # context 'failure'
|
|
313
|
+
|
|
314
|
+
end # context 'without group_id'
|
|
315
|
+
end # describe '#perform!'
|
|
99
316
|
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
4
|
+
|
|
5
|
+
describe Backup::Notifier::Prowl do
|
|
6
|
+
let(:notifier) do
|
|
7
|
+
Backup::Notifier::Prowl.new do |prowl|
|
|
8
|
+
prowl.application = 'application'
|
|
9
|
+
prowl.api_key = 'api_key'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#initialize' do
|
|
14
|
+
it 'sets the correct defaults' do
|
|
15
|
+
notifier.application = 'application'
|
|
16
|
+
notifier.api_key = 'api_key'
|
|
17
|
+
|
|
18
|
+
notifier.on_success.should == true
|
|
19
|
+
notifier.on_warning.should == true
|
|
20
|
+
notifier.on_failure.should == true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'uses and overrides configuration defaults' do
|
|
24
|
+
Backup::Configuration::Notifier::Prowl.defaults do |notifier|
|
|
25
|
+
notifier.application = 'my_default_application'
|
|
26
|
+
notifier.on_success = false
|
|
27
|
+
end
|
|
28
|
+
prowl = Backup::Notifier::Prowl.new do |notifier|
|
|
29
|
+
notifier.api_key = 'my_own_api_key'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
prowl.application.should == 'my_default_application'
|
|
33
|
+
prowl.api_key.should == 'my_own_api_key'
|
|
34
|
+
prowl.on_success.should == false
|
|
35
|
+
prowl.on_warning.should == true
|
|
36
|
+
prowl.on_failure.should == true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'creates a new Prowler::Application' do
|
|
40
|
+
notifier.prowl_client.should be_an_instance_of Prowler::Application
|
|
41
|
+
notifier.prowl_client.application.should == notifier.application
|
|
42
|
+
notifier.prowl_client.api_key.should == notifier.api_key
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#perform!' do
|
|
47
|
+
let(:model) { Backup::Model.new('trigger', 'label') {} }
|
|
48
|
+
let(:message_a) { '[Backup::%s]' }
|
|
49
|
+
let(:message_b) { 'label (trigger)' }
|
|
50
|
+
|
|
51
|
+
before do
|
|
52
|
+
notifier.on_success = false
|
|
53
|
+
notifier.on_warning = false
|
|
54
|
+
notifier.on_failure = false
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context 'success' do
|
|
58
|
+
|
|
59
|
+
context 'when on_success is true' do
|
|
60
|
+
before { notifier.on_success = true }
|
|
61
|
+
|
|
62
|
+
it 'sends success message' do
|
|
63
|
+
notifier.expects(:log!)
|
|
64
|
+
notifier.prowl_client.expects(:notify).
|
|
65
|
+
with(message_a % 'Success', message_b)
|
|
66
|
+
|
|
67
|
+
notifier.perform!(model)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'when on_success is false' do
|
|
72
|
+
it 'sends no message' do
|
|
73
|
+
notifier.expects(:log!).never
|
|
74
|
+
notifier.expects(:notify!).never
|
|
75
|
+
notifier.prowl_client.expects(:notify).never
|
|
76
|
+
|
|
77
|
+
notifier.perform!(model)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end # context 'success'
|
|
82
|
+
|
|
83
|
+
context 'warning' do
|
|
84
|
+
before { Backup::Logger.stubs(:has_warnings?).returns(true) }
|
|
85
|
+
|
|
86
|
+
context 'when on_success is true' do
|
|
87
|
+
before { notifier.on_success = true }
|
|
88
|
+
|
|
89
|
+
it 'sends warning message' do
|
|
90
|
+
notifier.expects(:log!)
|
|
91
|
+
notifier.prowl_client.expects(:notify).
|
|
92
|
+
with(message_a % 'Warning', message_b)
|
|
93
|
+
|
|
94
|
+
notifier.perform!(model)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'when on_warning is true' do
|
|
99
|
+
before { notifier.on_warning = true }
|
|
100
|
+
|
|
101
|
+
it 'sends warning message' do
|
|
102
|
+
notifier.expects(:log!)
|
|
103
|
+
notifier.prowl_client.expects(:notify).
|
|
104
|
+
with(message_a % 'Warning', message_b)
|
|
105
|
+
|
|
106
|
+
notifier.perform!(model)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
context 'when on_success and on_warning are false' do
|
|
111
|
+
it 'sends no message' do
|
|
112
|
+
notifier.expects(:log!).never
|
|
113
|
+
notifier.expects(:notify!).never
|
|
114
|
+
notifier.prowl_client.expects(:notify).never
|
|
115
|
+
|
|
116
|
+
notifier.perform!(model)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
end # context 'warning'
|
|
121
|
+
|
|
122
|
+
context 'failure' do
|
|
123
|
+
|
|
124
|
+
context 'when on_failure is true' do
|
|
125
|
+
before { notifier.on_failure = true }
|
|
126
|
+
|
|
127
|
+
it 'sends failure message' do
|
|
128
|
+
notifier.expects(:log!)
|
|
129
|
+
notifier.prowl_client.expects(:notify).
|
|
130
|
+
with(message_a % 'Failure', message_b)
|
|
131
|
+
|
|
132
|
+
notifier.perform!(model, Exception.new)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
context 'when on_failure is false' do
|
|
137
|
+
it 'sends no message' do
|
|
138
|
+
notifier.expects(:log!).never
|
|
139
|
+
notifier.expects(:notify!).never
|
|
140
|
+
notifier.prowl_client.expects(:notify).never
|
|
141
|
+
|
|
142
|
+
notifier.perform!(model, Exception.new)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
end # context 'failure'
|
|
147
|
+
|
|
148
|
+
end # describe '#perform!'
|
|
149
|
+
end
|