backup-agoddard 3.0.27
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup-agoddard might be problematic. Click here for more details.
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Guardfile +23 -0
- data/LICENSE.md +24 -0
- data/README.md +478 -0
- data/backup.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +133 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +93 -0
- data/lib/backup/cli/utility.rb +255 -0
- data/lib/backup/compressor/base.rb +35 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +50 -0
- data/lib/backup/compressor/lzma.rb +52 -0
- data/lib/backup/compressor/pbzip2.rb +59 -0
- data/lib/backup/config.rb +174 -0
- data/lib/backup/configuration.rb +33 -0
- data/lib/backup/configuration/helpers.rb +130 -0
- data/lib/backup/configuration/store.rb +24 -0
- data/lib/backup/database/base.rb +53 -0
- data/lib/backup/database/mongodb.rb +230 -0
- data/lib/backup/database/mysql.rb +160 -0
- data/lib/backup/database/postgresql.rb +144 -0
- data/lib/backup/database/redis.rb +136 -0
- data/lib/backup/database/riak.rb +67 -0
- data/lib/backup/dependency.rb +108 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +760 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/hooks.rb +68 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +409 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +155 -0
- data/lib/backup/notifier/hipchat.rb +93 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/pushover.rb +88 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +100 -0
- data/lib/backup/pipeline.rb +110 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +99 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +178 -0
- data/lib/backup/storage/ftp.rb +119 -0
- data/lib/backup/storage/local.rb +82 -0
- data/lib/backup/storage/ninefold.rb +116 -0
- data/lib/backup/storage/rsync.rb +149 -0
- data/lib/backup/storage/s3.rb +94 -0
- data/lib/backup/storage/scp.rb +99 -0
- data/lib/backup/storage/sftp.rb +108 -0
- data/lib/backup/syncer/base.rb +46 -0
- data/lib/backup/syncer/cloud/base.rb +247 -0
- data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
- data/lib/backup/syncer/cloud/s3.rb +68 -0
- data/lib/backup/syncer/rsync/base.rb +49 -0
- data/lib/backup/syncer/rsync/local.rb +55 -0
- data/lib/backup/syncer/rsync/pull.rb +36 -0
- data/lib/backup/syncer/rsync/push.rb +116 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec-live/.gitignore +6 -0
- data/spec-live/README +7 -0
- data/spec-live/backups/config.rb +83 -0
- data/spec-live/backups/config.yml.template +46 -0
- data/spec-live/backups/models.rb +184 -0
- data/spec-live/compressor/custom_spec.rb +30 -0
- data/spec-live/compressor/gzip_spec.rb +30 -0
- data/spec-live/encryptor/gpg_keys.rb +239 -0
- data/spec-live/encryptor/gpg_spec.rb +287 -0
- data/spec-live/notifier/mail_spec.rb +121 -0
- data/spec-live/spec_helper.rb +151 -0
- data/spec-live/storage/dropbox_spec.rb +151 -0
- data/spec-live/storage/local_spec.rb +83 -0
- data/spec-live/storage/scp_spec.rb +193 -0
- data/spec-live/syncer/cloud/s3_spec.rb +124 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +312 -0
- data/spec/cli/helpers_spec.rb +301 -0
- data/spec/cli/utility_spec.rb +411 -0
- data/spec/compressor/base_spec.rb +52 -0
- data/spec/compressor/bzip2_spec.rb +217 -0
- data/spec/compressor/custom_spec.rb +106 -0
- data/spec/compressor/gzip_spec.rb +217 -0
- data/spec/compressor/lzma_spec.rb +123 -0
- data/spec/compressor/pbzip2_spec.rb +165 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/helpers_spec.rb +247 -0
- data/spec/configuration/store_spec.rb +39 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/database/base_spec.rb +63 -0
- data/spec/database/mongodb_spec.rb +510 -0
- data/spec/database/mysql_spec.rb +411 -0
- data/spec/database/postgresql_spec.rb +353 -0
- data/spec/database/redis_spec.rb +334 -0
- data/spec/database/riak_spec.rb +176 -0
- data/spec/dependency_spec.rb +51 -0
- data/spec/encryptor/base_spec.rb +40 -0
- data/spec/encryptor/gpg_spec.rb +909 -0
- data/spec/encryptor/open_ssl_spec.rb +148 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/hooks_spec.rb +35 -0
- data/spec/logger_spec.rb +367 -0
- data/spec/model_spec.rb +694 -0
- data/spec/notifier/base_spec.rb +104 -0
- data/spec/notifier/campfire_spec.rb +217 -0
- data/spec/notifier/hipchat_spec.rb +211 -0
- data/spec/notifier/mail_spec.rb +316 -0
- data/spec/notifier/prowl_spec.rb +138 -0
- data/spec/notifier/pushover_spec.rb +123 -0
- data/spec/notifier/twitter_spec.rb +153 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +213 -0
- data/spec/pipeline_spec.rb +259 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +166 -0
- data/spec/storage/cloudfiles_spec.rb +254 -0
- data/spec/storage/cycler_spec.rb +247 -0
- data/spec/storage/dropbox_spec.rb +480 -0
- data/spec/storage/ftp_spec.rb +271 -0
- data/spec/storage/local_spec.rb +259 -0
- data/spec/storage/ninefold_spec.rb +343 -0
- data/spec/storage/rsync_spec.rb +362 -0
- data/spec/storage/s3_spec.rb +245 -0
- data/spec/storage/scp_spec.rb +233 -0
- data/spec/storage/sftp_spec.rb +244 -0
- data/spec/syncer/base_spec.rb +109 -0
- data/spec/syncer/cloud/base_spec.rb +515 -0
- data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
- data/spec/syncer/cloud/s3_spec.rb +174 -0
- data/spec/syncer/rsync/base_spec.rb +98 -0
- data/spec/syncer/rsync/local_spec.rb +149 -0
- data/spec/syncer/rsync/pull_spec.rb +98 -0
- data/spec/syncer/rsync/push_spec.rb +333 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +4 -0
- data/templates/cli/utility/compressor/custom +11 -0
- data/templates/cli/utility/compressor/gzip +4 -0
- data/templates/cli/utility/compressor/lzma +10 -0
- data/templates/cli/utility/compressor/pbzip2 +10 -0
- data/templates/cli/utility/config +32 -0
- data/templates/cli/utility/database/mongodb +18 -0
- data/templates/cli/utility/database/mysql +21 -0
- data/templates/cli/utility/database/postgresql +17 -0
- data/templates/cli/utility/database/redis +16 -0
- data/templates/cli/utility/database/riak +11 -0
- data/templates/cli/utility/encryptor/gpg +27 -0
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/templates/cli/utility/notifier/campfire +12 -0
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/templates/cli/utility/notifier/mail +22 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/templates/cli/utility/notifier/pushover +11 -0
- data/templates/cli/utility/notifier/twitter +13 -0
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloud_files +22 -0
- data/templates/cli/utility/storage/dropbox +20 -0
- data/templates/cli/utility/storage/ftp +12 -0
- data/templates/cli/utility/storage/local +7 -0
- data/templates/cli/utility/storage/ninefold +9 -0
- data/templates/cli/utility/storage/rsync +11 -0
- data/templates/cli/utility/storage/s3 +19 -0
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/templates/cli/utility/syncer/cloud_files +46 -0
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/rsync_pull +17 -0
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/cli/utility/syncer/s3 +43 -0
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +277 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Backup::Notifier::Base' do
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
+
let(:notifier) { Backup::Notifier::Base.new(model) }
|
8
|
+
|
9
|
+
it 'should include Configuration::Helpers' do
|
10
|
+
Backup::Notifier::Base.
|
11
|
+
include?(Backup::Configuration::Helpers).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#initialize' do
|
15
|
+
after { Backup::Notifier::Base.clear_defaults! }
|
16
|
+
|
17
|
+
it 'should load pre-configured defaults' do
|
18
|
+
Backup::Notifier::Base.any_instance.expects(:load_defaults!)
|
19
|
+
notifier
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should set a reference to the model' do
|
23
|
+
notifier.instance_variable_get(:@model).should == model
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when no pre-configured defaults have been set' do
|
27
|
+
it 'should set default values' do
|
28
|
+
notifier.on_success.should == true
|
29
|
+
notifier.on_warning.should == true
|
30
|
+
notifier.on_failure.should == true
|
31
|
+
end
|
32
|
+
end # context 'when no pre-configured defaults have been set'
|
33
|
+
|
34
|
+
context 'when pre-configured defaults have been set' do
|
35
|
+
before do
|
36
|
+
Backup::Notifier::Base.defaults do |n|
|
37
|
+
n.on_success = false
|
38
|
+
n.on_warning = false
|
39
|
+
n.on_failure = false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should use pre-configured defaults' do
|
44
|
+
notifier.on_success.should be_false
|
45
|
+
notifier.on_warning.should be_false
|
46
|
+
notifier.on_failure.should be_false
|
47
|
+
end
|
48
|
+
end # context 'when pre-configured defaults have been set'
|
49
|
+
end # describe '#initialize'
|
50
|
+
|
51
|
+
describe '#perform!' do
|
52
|
+
before do
|
53
|
+
notifier.expects(:log!)
|
54
|
+
Backup::Template.expects(:new).with({:model => model})
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when failure is false' do
|
58
|
+
context 'when no warnings were issued' do
|
59
|
+
before do
|
60
|
+
Backup::Logger.expects(:has_warnings?).returns(false)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should call #notify! with :success' do
|
64
|
+
notifier.expects(:notify!).with(:success)
|
65
|
+
notifier.perform!
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when warnings were issued' do
|
70
|
+
before do
|
71
|
+
Backup::Logger.expects(:has_warnings?).returns(true)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should call #notify! with :warning' do
|
75
|
+
notifier.expects(:notify!).with(:warning)
|
76
|
+
notifier.perform!
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end # context 'when failure is false'
|
80
|
+
|
81
|
+
context 'when failure is true' do
|
82
|
+
it 'should call #notify with :failure' do
|
83
|
+
notifier.expects(:notify!).with(:failure)
|
84
|
+
notifier.perform!(true)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end # describe '#perform!'
|
88
|
+
|
89
|
+
describe '#notifier_name' do
|
90
|
+
it 'should return class name without Backup:: namespace' do
|
91
|
+
notifier.send(:notifier_name).should == 'Notifier::Base'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#log!' do
|
96
|
+
it 'should log a message' do
|
97
|
+
Backup::Logger.expects(:message).with(
|
98
|
+
"Notifier::Base started notifying about the process."
|
99
|
+
)
|
100
|
+
notifier.send(:log!)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Notifier::Campfire do
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
+
let(:notifier) do
|
8
|
+
Backup::Notifier::Campfire.new(model) do |campfire|
|
9
|
+
campfire.api_token = 'token'
|
10
|
+
campfire.subdomain = 'subdomain'
|
11
|
+
campfire.room_id = 'room_id'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should be a subclass of Notifier::Base' do
|
16
|
+
Backup::Notifier::Campfire.
|
17
|
+
superclass.should == Backup::Notifier::Base
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#initialize' do
|
21
|
+
after { Backup::Notifier::Campfire.clear_defaults! }
|
22
|
+
|
23
|
+
it 'should load pre-configured defaults through Base' do
|
24
|
+
Backup::Notifier::Campfire.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.api_token.should == 'token'
|
35
|
+
notifier.subdomain.should == 'subdomain'
|
36
|
+
notifier.room_id.should == 'room_id'
|
37
|
+
|
38
|
+
notifier.on_success.should == true
|
39
|
+
notifier.on_warning.should == true
|
40
|
+
notifier.on_failure.should == true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should use default values if none are given' do
|
44
|
+
notifier = Backup::Notifier::Campfire.new(model)
|
45
|
+
notifier.api_token.should be_nil
|
46
|
+
notifier.subdomain.should be_nil
|
47
|
+
notifier.room_id.should be_nil
|
48
|
+
|
49
|
+
notifier.on_success.should == true
|
50
|
+
notifier.on_warning.should == true
|
51
|
+
notifier.on_failure.should == true
|
52
|
+
end
|
53
|
+
end # context 'when no pre-configured defaults have been set'
|
54
|
+
|
55
|
+
context 'when pre-configured defaults have been set' do
|
56
|
+
before do
|
57
|
+
Backup::Notifier::Campfire.defaults do |n|
|
58
|
+
n.api_token = 'some_token'
|
59
|
+
n.subdomain = 'some_subdomain'
|
60
|
+
n.room_id = 'some_room_id'
|
61
|
+
|
62
|
+
n.on_success = false
|
63
|
+
n.on_warning = false
|
64
|
+
n.on_failure = false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should use pre-configured defaults' do
|
69
|
+
notifier = Backup::Notifier::Campfire.new(model)
|
70
|
+
notifier.api_token.should == 'some_token'
|
71
|
+
notifier.subdomain.should == 'some_subdomain'
|
72
|
+
notifier.room_id.should == 'some_room_id'
|
73
|
+
|
74
|
+
notifier.on_success.should == false
|
75
|
+
notifier.on_warning.should == false
|
76
|
+
notifier.on_failure.should == false
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should override pre-configured defaults' do
|
80
|
+
notifier = Backup::Notifier::Campfire.new(model) do |n|
|
81
|
+
n.api_token = 'new_token'
|
82
|
+
n.subdomain = 'new_subdomain'
|
83
|
+
n.room_id = 'new_room_id'
|
84
|
+
|
85
|
+
n.on_success = false
|
86
|
+
n.on_warning = true
|
87
|
+
n.on_failure = true
|
88
|
+
end
|
89
|
+
|
90
|
+
notifier.api_token.should == 'new_token'
|
91
|
+
notifier.subdomain.should == 'new_subdomain'
|
92
|
+
notifier.room_id.should == 'new_room_id'
|
93
|
+
|
94
|
+
notifier.on_success.should == false
|
95
|
+
notifier.on_warning.should == true
|
96
|
+
notifier.on_failure.should == true
|
97
|
+
end
|
98
|
+
end # context 'when pre-configured defaults have been set'
|
99
|
+
end # describe '#initialize'
|
100
|
+
|
101
|
+
describe '#notify!' do
|
102
|
+
context 'when status is :success' do
|
103
|
+
it 'should send Success message' do
|
104
|
+
notifier.expects(:send_message).with(
|
105
|
+
'[Backup::Success] test label (test_trigger)'
|
106
|
+
)
|
107
|
+
notifier.send(:notify!, :success)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when status is :warning' do
|
112
|
+
it 'should send Warning message' do
|
113
|
+
notifier.expects(:send_message).with(
|
114
|
+
'[Backup::Warning] test label (test_trigger)'
|
115
|
+
)
|
116
|
+
notifier.send(:notify!, :warning)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when status is :failure' do
|
121
|
+
it 'should send Failure message' do
|
122
|
+
notifier.expects(:send_message).with(
|
123
|
+
'[Backup::Failure] test label (test_trigger)'
|
124
|
+
)
|
125
|
+
notifier.send(:notify!, :failure)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end # describe '#notify!'
|
129
|
+
|
130
|
+
describe '#send_message' do
|
131
|
+
it 'should send a message' do
|
132
|
+
room = mock
|
133
|
+
Backup::Notifier::Campfire::Interface.expects(:room).
|
134
|
+
with('room_id', 'subdomain', 'token').returns(room)
|
135
|
+
room.expects(:message).with('a message')
|
136
|
+
|
137
|
+
notifier.send(:send_message, 'a message')
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
describe 'Backup::Notifier::Campfire::Interface' do
|
144
|
+
let(:interface) { Backup::Notifier::Campfire::Interface }
|
145
|
+
|
146
|
+
it 'should include HTTParty' do
|
147
|
+
interface.included_modules.should include(HTTParty)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should set the proper headers' do
|
151
|
+
interface.headers['Content-Type'].should == 'application/json'
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '.room' do
|
155
|
+
let(:room) { mock }
|
156
|
+
|
157
|
+
it 'should create and return a new Room' do
|
158
|
+
Backup::Notifier::Campfire::Room.expects(:new).
|
159
|
+
with('room_id', 'subdomain', 'api_token').returns(room)
|
160
|
+
|
161
|
+
interface.room('room_id', 'subdomain', 'api_token').should == room
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'Backup::Notifier::Campfire::Room' do
|
167
|
+
let(:room) do
|
168
|
+
Backup::Notifier::Campfire::Room.new('room_id', 'subdomain', 'api_token')
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should set the given values for the room' do
|
172
|
+
room.room_id.should == 'room_id'
|
173
|
+
room.subdomain.should == 'subdomain'
|
174
|
+
room.api_token.should == 'api_token'
|
175
|
+
end
|
176
|
+
|
177
|
+
describe '#message' do
|
178
|
+
it 'should wrap #send_message' do
|
179
|
+
room.expects(:send_message).with('a message')
|
180
|
+
|
181
|
+
room.message('a message')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe '#send_message' do
|
186
|
+
it 'should pass a JSON formatted HTTParty.post to #post' do
|
187
|
+
room.expects(:post).with(
|
188
|
+
'speak', {
|
189
|
+
:body => MultiJson.encode(
|
190
|
+
{ :message => { :body => 'a message', :type => 'Textmessage' } }
|
191
|
+
)
|
192
|
+
}
|
193
|
+
)
|
194
|
+
room.send(:send_message, 'a message')
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe '#post' do
|
199
|
+
let(:interface) { Backup::Notifier::Campfire::Interface }
|
200
|
+
|
201
|
+
it 'should send an HTTParty.post with the given options through Interface' do
|
202
|
+
room.expects(:room_url_for).with('an_action').returns('a_room_url')
|
203
|
+
interface.expects(:base_uri).with('https://subdomain.campfirenow.com')
|
204
|
+
interface.expects(:basic_auth).with('api_token', 'x')
|
205
|
+
interface.expects(:post).with('a_room_url', { :hash => 'of options' })
|
206
|
+
|
207
|
+
room.send(:post, 'an_action', :hash => 'of options')
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '#room_url_for' do
|
212
|
+
it 'should return a properly formated url for the given action' do
|
213
|
+
room.send(:room_url_for, 'my_action').should ==
|
214
|
+
'/room/room_id/my_action.json'
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Notifier::Hipchat do
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
+
let(:notifier) do
|
8
|
+
Backup::Notifier::Hipchat.new(model) do |notifier|
|
9
|
+
notifier.token = 'token'
|
10
|
+
notifier.from = 'application'
|
11
|
+
notifier.rooms_notified = ['room1', 'room2']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should be a subclass of Notifier::Base' do
|
16
|
+
Backup::Notifier::Hipchat.
|
17
|
+
superclass.should == Backup::Notifier::Base
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#initialize' do
|
21
|
+
after { Backup::Notifier::Hipchat.clear_defaults! }
|
22
|
+
|
23
|
+
it 'should load pre-configured defaults through Base' do
|
24
|
+
Backup::Notifier::Hipchat.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.token.should == 'token'
|
35
|
+
notifier.from.should == 'application'
|
36
|
+
notifier.rooms_notified.should == ['room1', 'room2']
|
37
|
+
notifier.notify_users.should == false
|
38
|
+
notifier.success_color.should == 'yellow'
|
39
|
+
notifier.warning_color.should == 'yellow'
|
40
|
+
notifier.failure_color.should == 'yellow'
|
41
|
+
|
42
|
+
notifier.on_success.should == true
|
43
|
+
notifier.on_warning.should == true
|
44
|
+
notifier.on_failure.should == true
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should use default values if none are given' do
|
48
|
+
notifier = Backup::Notifier::Hipchat.new(model)
|
49
|
+
notifier.token.should be_nil
|
50
|
+
notifier.from.should be_nil
|
51
|
+
notifier.rooms_notified.should == []
|
52
|
+
notifier.notify_users.should == false
|
53
|
+
notifier.success_color.should == 'yellow'
|
54
|
+
notifier.warning_color.should == 'yellow'
|
55
|
+
notifier.failure_color.should == 'yellow'
|
56
|
+
|
57
|
+
notifier.on_success.should == true
|
58
|
+
notifier.on_warning.should == true
|
59
|
+
notifier.on_failure.should == true
|
60
|
+
end
|
61
|
+
end # context 'when no pre-configured defaults have been set'
|
62
|
+
|
63
|
+
context 'when pre-configured defaults have been set' do
|
64
|
+
before do
|
65
|
+
Backup::Notifier::Hipchat.defaults do |n|
|
66
|
+
n.token = 'old'
|
67
|
+
n.from = 'before'
|
68
|
+
n.success_color = 'green'
|
69
|
+
n.on_failure = false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should use pre-configured defaults' do
|
74
|
+
notifier = Backup::Notifier::Hipchat.new(model)
|
75
|
+
|
76
|
+
notifier.token.should == 'old'
|
77
|
+
notifier.from.should == 'before'
|
78
|
+
notifier.rooms_notified.should == []
|
79
|
+
notifier.notify_users.should == false
|
80
|
+
notifier.success_color.should == 'green'
|
81
|
+
notifier.warning_color.should == 'yellow'
|
82
|
+
notifier.failure_color.should == 'yellow'
|
83
|
+
|
84
|
+
notifier.on_success.should == true
|
85
|
+
notifier.on_warning.should == true
|
86
|
+
notifier.on_failure.should == false
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should override pre-configured defaults' do
|
90
|
+
notifier = Backup::Notifier::Hipchat.new(model) do |n|
|
91
|
+
n.token = 'new'
|
92
|
+
n.from = 'after'
|
93
|
+
n.failure_color = 'red'
|
94
|
+
n.on_success = false
|
95
|
+
n.on_failure = true
|
96
|
+
end
|
97
|
+
|
98
|
+
notifier.token.should == 'new'
|
99
|
+
notifier.from.should == 'after'
|
100
|
+
notifier.success_color.should == 'green'
|
101
|
+
notifier.warning_color.should == 'yellow'
|
102
|
+
notifier.failure_color.should == 'red'
|
103
|
+
|
104
|
+
notifier.on_success.should == false
|
105
|
+
notifier.on_warning.should == true
|
106
|
+
notifier.on_failure.should == true
|
107
|
+
end
|
108
|
+
end # context 'when pre-configured defaults have been set'
|
109
|
+
end # describe '#initialize'
|
110
|
+
|
111
|
+
describe '#notify!' do
|
112
|
+
before do
|
113
|
+
notifier.success_color = 'green'
|
114
|
+
notifier.warning_color = 'yellow'
|
115
|
+
notifier.failure_color = 'red'
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when status is :success' do
|
119
|
+
it 'should send Success message' do
|
120
|
+
notifier.expects(:send_message).with(
|
121
|
+
'[Backup::Success] test label (test_trigger)', 'green'
|
122
|
+
)
|
123
|
+
notifier.send(:notify!, :success)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when status is :warning' do
|
128
|
+
it 'should send Warning message' do
|
129
|
+
notifier.expects(:send_message).with(
|
130
|
+
'[Backup::Warning] test label (test_trigger)', 'yellow'
|
131
|
+
)
|
132
|
+
notifier.send(:notify!, :warning)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'when status is :failure' do
|
137
|
+
it 'should send Failure message' do
|
138
|
+
notifier.expects(:send_message).with(
|
139
|
+
'[Backup::Failure] test label (test_trigger)', 'red'
|
140
|
+
)
|
141
|
+
notifier.send(:notify!, :failure)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end # describe '#notify!'
|
145
|
+
|
146
|
+
describe '#send_message' do
|
147
|
+
let(:client) { mock }
|
148
|
+
let(:room) { mock }
|
149
|
+
|
150
|
+
it 'should handle rooms_notified being set as a single room string' do
|
151
|
+
notifier.rooms_notified = 'a_room'
|
152
|
+
HipChat::Client.expects(:new).with('token').returns(client)
|
153
|
+
client.expects(:[]).with('a_room').returns(room)
|
154
|
+
room.expects(:send).with(
|
155
|
+
'application',
|
156
|
+
'a message',
|
157
|
+
{:color => 'a color', :notify => false}
|
158
|
+
)
|
159
|
+
|
160
|
+
notifier.send(:send_message, 'a message', 'a color')
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when notify_users is set to true' do
|
164
|
+
before { notifier.notify_users = true }
|
165
|
+
|
166
|
+
it 'should notify rooms with :notify => true' do
|
167
|
+
HipChat::Client.expects(:new).with('token').returns(client)
|
168
|
+
|
169
|
+
client.expects(:[]).with('room1').returns(room)
|
170
|
+
room.expects(:send).with(
|
171
|
+
'application',
|
172
|
+
'a message',
|
173
|
+
{:color => 'a color', :notify => true}
|
174
|
+
)
|
175
|
+
|
176
|
+
client.expects(:[]).with('room2').returns(room)
|
177
|
+
room.expects(:send).with(
|
178
|
+
'application',
|
179
|
+
'a message',
|
180
|
+
{:color => 'a color', :notify => true}
|
181
|
+
)
|
182
|
+
|
183
|
+
notifier.send(:send_message, 'a message', 'a color')
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'when notify_users is set to false' do
|
188
|
+
before { notifier.notify_users = false }
|
189
|
+
|
190
|
+
it 'should notify rooms with :notify => false' do
|
191
|
+
HipChat::Client.expects(:new).with('token').returns(client)
|
192
|
+
|
193
|
+
client.expects(:[]).with('room1').returns(room)
|
194
|
+
room.expects(:send).with(
|
195
|
+
'application',
|
196
|
+
'a message',
|
197
|
+
{:color => 'a color', :notify => false}
|
198
|
+
)
|
199
|
+
|
200
|
+
client.expects(:[]).with('room2').returns(room)
|
201
|
+
room.expects(:send).with(
|
202
|
+
'application',
|
203
|
+
'a message',
|
204
|
+
{:color => 'a color', :notify => false}
|
205
|
+
)
|
206
|
+
|
207
|
+
notifier.send(:send_message, 'a message', 'a color')
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|