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.
- data/.gitignore +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Gemfile.lock +130 -0
- data/Guardfile +21 -0
- data/LICENSE.md +24 -0
- data/README.md +476 -0
- data/backup_checksum.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +217 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/checksum/base.rb +44 -0
- data/lib/backup/checksum/shasum.rb +16 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +88 -0
- data/lib/backup/cli/utility.rb +247 -0
- data/lib/backup/compressor/base.rb +29 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/gzip.rb +47 -0
- data/lib/backup/compressor/lzma.rb +50 -0
- data/lib/backup/compressor/pbzip2.rb +56 -0
- data/lib/backup/config.rb +173 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/checksum/base.rb +9 -0
- data/lib/backup/configuration/checksum/shasum.rb +9 -0
- data/lib/backup/configuration/compressor/base.rb +9 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/compressor/lzma.rb +23 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/base.rb +19 -0
- data/lib/backup/configuration/database/mongodb.rb +49 -0
- data/lib/backup/configuration/database/mysql.rb +42 -0
- data/lib/backup/configuration/database/postgresql.rb +41 -0
- data/lib/backup/configuration/database/redis.rb +39 -0
- data/lib/backup/configuration/database/riak.rb +29 -0
- data/lib/backup/configuration/encryptor/base.rb +9 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +32 -0
- data/lib/backup/configuration/helpers.rb +52 -0
- data/lib/backup/configuration/notifier/base.rb +28 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +112 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +25 -0
- data/lib/backup/configuration/storage/dropbox.rb +58 -0
- data/lib/backup/configuration/storage/ftp.rb +29 -0
- data/lib/backup/configuration/storage/local.rb +17 -0
- data/lib/backup/configuration/storage/ninefold.rb +20 -0
- data/lib/backup/configuration/storage/rsync.rb +29 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/cloud.rb +23 -0
- data/lib/backup/configuration/syncer/cloud_files.rb +30 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +23 -0
- data/lib/backup/database/base.rb +59 -0
- data/lib/backup/database/mongodb.rb +232 -0
- data/lib/backup/database/mysql.rb +163 -0
- data/lib/backup/database/postgresql.rb +146 -0
- data/lib/backup/database/redis.rb +139 -0
- data/lib/backup/database/riak.rb +69 -0
- data/lib/backup/dependency.rb +114 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +80 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +386 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +168 -0
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/presently.rb +88 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +51 -0
- data/lib/backup/packager.rb +108 -0
- data/lib/backup/pipeline.rb +107 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +119 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +181 -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 +42 -0
- data/lib/backup/syncer/cloud.rb +190 -0
- data/lib/backup/syncer/cloud_files.rb +56 -0
- data/lib/backup/syncer/rsync/base.rb +52 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +47 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +176 -0
- data/spec/cli/utility_spec.rb +363 -0
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +83 -0
- data/spec/compressor/gzip_spec.rb +83 -0
- data/spec/compressor/lzma_spec.rb +83 -0
- data/spec/compressor/pbzip2_spec.rb +124 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/bzip2_spec.rb +29 -0
- data/spec/configuration/compressor/gzip_spec.rb +29 -0
- data/spec/configuration/compressor/lzma_spec.rb +29 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +17 -0
- data/spec/configuration/database/mongodb_spec.rb +56 -0
- data/spec/configuration/database/mysql_spec.rb +53 -0
- data/spec/configuration/database/postgresql_spec.rb +53 -0
- data/spec/configuration/database/redis_spec.rb +50 -0
- data/spec/configuration/database/riak_spec.rb +35 -0
- data/spec/configuration/encryptor/gpg_spec.rb +26 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +35 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +32 -0
- data/spec/configuration/notifier/hipchat_spec.rb +44 -0
- data/spec/configuration/notifier/mail_spec.rb +71 -0
- data/spec/configuration/notifier/presently_spec.rb +35 -0
- data/spec/configuration/notifier/prowl_spec.rb +29 -0
- data/spec/configuration/notifier/twitter_spec.rb +35 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +41 -0
- data/spec/configuration/storage/dropbox_spec.rb +38 -0
- data/spec/configuration/storage/ftp_spec.rb +44 -0
- data/spec/configuration/storage/local_spec.rb +29 -0
- data/spec/configuration/storage/ninefold_spec.rb +32 -0
- data/spec/configuration/storage/rsync_spec.rb +41 -0
- data/spec/configuration/storage/s3_spec.rb +38 -0
- data/spec/configuration/storage/scp_spec.rb +41 -0
- data/spec/configuration/storage/sftp_spec.rb +41 -0
- data/spec/configuration/syncer/cloud_files_spec.rb +44 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/push_spec.rb +43 -0
- data/spec/configuration/syncer/s3_spec.rb +38 -0
- data/spec/database/base_spec.rb +54 -0
- data/spec/database/mongodb_spec.rb +428 -0
- data/spec/database/mysql_spec.rb +335 -0
- data/spec/database/postgresql_spec.rb +278 -0
- data/spec/database/redis_spec.rb +260 -0
- data/spec/database/riak_spec.rb +108 -0
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +134 -0
- data/spec/encryptor/open_ssl_spec.rb +129 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/logger_spec.rb +363 -0
- data/spec/model_spec.rb +649 -0
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +199 -0
- data/spec/notifier/hipchat_spec.rb +188 -0
- data/spec/notifier/mail_spec.rb +280 -0
- data/spec/notifier/presently_spec.rb +181 -0
- data/spec/notifier/prowl_spec.rb +117 -0
- data/spec/notifier/twitter_spec.rb +132 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +225 -0
- data/spec/pipeline_spec.rb +257 -0
- data/spec/spec_helper.rb +59 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +160 -0
- data/spec/storage/cloudfiles_spec.rb +230 -0
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +370 -0
- data/spec/storage/ftp_spec.rb +247 -0
- data/spec/storage/local_spec.rb +235 -0
- data/spec/storage/ninefold_spec.rb +319 -0
- data/spec/storage/rsync_spec.rb +345 -0
- data/spec/storage/s3_spec.rb +221 -0
- data/spec/storage/scp_spec.rb +209 -0
- data/spec/storage/sftp_spec.rb +220 -0
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/cloud_files_spec.rb +192 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +192 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +7 -0
- data/templates/cli/utility/compressor/gzip +7 -0
- data/templates/cli/utility/compressor/lzma +7 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -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 +12 -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/presently +13 -0
- data/templates/cli/utility/notifier/prowl +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 +48 -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 +45 -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 +311 -0
@@ -0,0 +1,89 @@
|
|
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
|
+
describe '#initialize' do
|
10
|
+
|
11
|
+
it "sets the correct defaults" do
|
12
|
+
notifier.on_success.should == true
|
13
|
+
notifier.on_warning.should == true
|
14
|
+
notifier.on_failure.should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when using configuration defaults' do
|
18
|
+
after { Backup::Configuration::Notifier::Base.clear_defaults! }
|
19
|
+
|
20
|
+
it 'uses configuration defaults' do
|
21
|
+
Backup::Configuration::Notifier::Base.defaults do |notifier|
|
22
|
+
notifier.on_success = false
|
23
|
+
notifier.on_warning = false
|
24
|
+
notifier.on_failure = false
|
25
|
+
end
|
26
|
+
|
27
|
+
base = Backup::Notifier::Base.new(model)
|
28
|
+
base.on_success.should == false
|
29
|
+
base.on_warning.should == false
|
30
|
+
base.on_failure.should == false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end # describe '#initialize'
|
35
|
+
|
36
|
+
describe '#perform!' do
|
37
|
+
before do
|
38
|
+
notifier.expects(:log!)
|
39
|
+
Backup::Template.expects(:new).with({:model => model})
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when failure is false' do
|
43
|
+
context 'when no warnings were issued' do
|
44
|
+
before do
|
45
|
+
Backup::Logger.expects(:has_warnings?).returns(false)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should call #notify! with :success' do
|
49
|
+
notifier.expects(:notify!).with(:success)
|
50
|
+
notifier.perform!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when warnings were issued' do
|
55
|
+
before do
|
56
|
+
Backup::Logger.expects(:has_warnings?).returns(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should call #notify! with :warning' do
|
60
|
+
notifier.expects(:notify!).with(:warning)
|
61
|
+
notifier.perform!
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end # context 'when failure is false'
|
65
|
+
|
66
|
+
context 'when failure is true' do
|
67
|
+
it 'should call #notify with :failure' do
|
68
|
+
notifier.expects(:notify!).with(:failure)
|
69
|
+
notifier.perform!(true)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end # describe '#perform!'
|
73
|
+
|
74
|
+
describe '#notifier_name' do
|
75
|
+
it 'should return class name without Backup:: namespace' do
|
76
|
+
notifier.send(:notifier_name).should == 'Notifier::Base'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#log!' do
|
81
|
+
it 'should log a message' do
|
82
|
+
Backup::Logger.expects(:message).with(
|
83
|
+
"Notifier::Base started notifying about the process."
|
84
|
+
)
|
85
|
+
notifier.send(:log!)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,199 @@
|
|
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
|
+
describe '#initialize' do
|
16
|
+
it 'should sets the correct values' do
|
17
|
+
notifier.api_token.should == 'token'
|
18
|
+
notifier.subdomain.should == 'subdomain'
|
19
|
+
notifier.room_id.should == 'room_id'
|
20
|
+
|
21
|
+
notifier.on_success.should == true
|
22
|
+
notifier.on_warning.should == true
|
23
|
+
notifier.on_failure.should == true
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when using configuration defaults' do
|
27
|
+
after { Backup::Configuration::Notifier::Campfire.clear_defaults! }
|
28
|
+
|
29
|
+
it 'should use the configuration defaults' do
|
30
|
+
Backup::Configuration::Notifier::Campfire.defaults do |campfire|
|
31
|
+
campfire.api_token = 'some_token'
|
32
|
+
campfire.subdomain = 'some_subdomain'
|
33
|
+
campfire.room_id = 'some_room_id'
|
34
|
+
|
35
|
+
campfire.on_success = false
|
36
|
+
campfire.on_warning = false
|
37
|
+
campfire.on_failure = false
|
38
|
+
end
|
39
|
+
notifier = Backup::Notifier::Campfire.new(model)
|
40
|
+
notifier.api_token.should == 'some_token'
|
41
|
+
notifier.subdomain.should == 'some_subdomain'
|
42
|
+
notifier.room_id.should == 'some_room_id'
|
43
|
+
|
44
|
+
notifier.on_success.should == false
|
45
|
+
notifier.on_warning.should == false
|
46
|
+
notifier.on_failure.should == false
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should override the configuration defaults' do
|
50
|
+
Backup::Configuration::Notifier::Campfire.defaults do |campfire|
|
51
|
+
campfire.api_token = 'old_token'
|
52
|
+
campfire.subdomain = 'old_subdomain'
|
53
|
+
campfire.room_id = 'old_room_id'
|
54
|
+
|
55
|
+
campfire.on_success = true
|
56
|
+
campfire.on_warning = false
|
57
|
+
campfire.on_failure = false
|
58
|
+
end
|
59
|
+
notifier = Backup::Notifier::Campfire.new(model) do |campfire|
|
60
|
+
campfire.api_token = 'new_token'
|
61
|
+
campfire.subdomain = 'new_subdomain'
|
62
|
+
campfire.room_id = 'new_room_id'
|
63
|
+
|
64
|
+
campfire.on_success = false
|
65
|
+
campfire.on_warning = true
|
66
|
+
campfire.on_failure = true
|
67
|
+
end
|
68
|
+
|
69
|
+
notifier.api_token.should == 'new_token'
|
70
|
+
notifier.subdomain.should == 'new_subdomain'
|
71
|
+
notifier.room_id.should == 'new_room_id'
|
72
|
+
|
73
|
+
notifier.on_success.should == false
|
74
|
+
notifier.on_warning.should == true
|
75
|
+
notifier.on_failure.should == true
|
76
|
+
end
|
77
|
+
end # context 'when using configuration defaults'
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#notify!' do
|
81
|
+
context 'when status is :success' do
|
82
|
+
it 'should send Success message' do
|
83
|
+
notifier.expects(:send_message).with(
|
84
|
+
'[Backup::Success] test label (test_trigger)'
|
85
|
+
)
|
86
|
+
notifier.send(:notify!, :success)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when status is :warning' do
|
91
|
+
it 'should send Warning message' do
|
92
|
+
notifier.expects(:send_message).with(
|
93
|
+
'[Backup::Warning] test label (test_trigger)'
|
94
|
+
)
|
95
|
+
notifier.send(:notify!, :warning)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when status is :failure' do
|
100
|
+
it 'should send Failure message' do
|
101
|
+
notifier.expects(:send_message).with(
|
102
|
+
'[Backup::Failure] test label (test_trigger)'
|
103
|
+
)
|
104
|
+
notifier.send(:notify!, :failure)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end # describe '#notify!'
|
108
|
+
|
109
|
+
describe '#send_message' do
|
110
|
+
it 'should send a message' do
|
111
|
+
room = mock
|
112
|
+
Backup::Notifier::Campfire::Interface.expects(:room).
|
113
|
+
with('room_id', 'subdomain', 'token').returns(room)
|
114
|
+
room.expects(:message).with('a message')
|
115
|
+
|
116
|
+
notifier.send(:send_message, 'a message')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'Backup::Notifier::Campfire::Interface' do
|
123
|
+
let(:interface) { Backup::Notifier::Campfire::Interface }
|
124
|
+
|
125
|
+
it 'should include HTTParty' do
|
126
|
+
interface.included_modules.should include(HTTParty)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should set the proper headers' do
|
130
|
+
interface.headers['Content-Type'].should == 'application/json'
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '.room' do
|
134
|
+
let(:room) { mock }
|
135
|
+
|
136
|
+
it 'should create and return a new Room' do
|
137
|
+
Backup::Notifier::Campfire::Room.expects(:new).
|
138
|
+
with('room_id', 'subdomain', 'api_token').returns(room)
|
139
|
+
|
140
|
+
interface.room('room_id', 'subdomain', 'api_token').should == room
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe 'Backup::Notifier::Campfire::Room' do
|
146
|
+
let(:room) do
|
147
|
+
Backup::Notifier::Campfire::Room.new('room_id', 'subdomain', 'api_token')
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should set the given values for the room' do
|
151
|
+
room.room_id.should == 'room_id'
|
152
|
+
room.subdomain.should == 'subdomain'
|
153
|
+
room.api_token.should == 'api_token'
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#message' do
|
157
|
+
it 'should wrap #send_message' do
|
158
|
+
room.expects(:send_message).with('a message')
|
159
|
+
|
160
|
+
room.message('a message')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#send_message' do
|
165
|
+
it 'should pass a JSON formatted HTTParty.post to #post' do
|
166
|
+
room.expects(:post).with('speak',
|
167
|
+
{
|
168
|
+
:body => {
|
169
|
+
:message => {
|
170
|
+
:body => 'a message',
|
171
|
+
:type => 'Textmessage'
|
172
|
+
}
|
173
|
+
}.to_json
|
174
|
+
}
|
175
|
+
)
|
176
|
+
room.send(:send_message, 'a message')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#post' do
|
181
|
+
let(:interface) { Backup::Notifier::Campfire::Interface }
|
182
|
+
|
183
|
+
it 'should send an HTTParty.post with the given options through Interface' do
|
184
|
+
room.expects(:room_url_for).with('an_action').returns('a_room_url')
|
185
|
+
interface.expects(:base_uri).with('https://subdomain.campfirenow.com')
|
186
|
+
interface.expects(:basic_auth).with('api_token', 'x')
|
187
|
+
interface.expects(:post).with('a_room_url', { :hash => 'of options' })
|
188
|
+
|
189
|
+
room.send(:post, 'an_action', :hash => 'of options')
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe '#room_url_for' do
|
194
|
+
it 'should return a properly formated url for the given action' do
|
195
|
+
room.send(:room_url_for, 'my_action').should ==
|
196
|
+
'/room/room_id/my_action.json'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,188 @@
|
|
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
|
+
describe '#initialize' do
|
16
|
+
|
17
|
+
it 'should set the correct values and defaults' do
|
18
|
+
notifier.token.should == 'token'
|
19
|
+
notifier.from.should == 'application'
|
20
|
+
notifier.rooms_notified.should == ['room1', 'room2']
|
21
|
+
notifier.notify_users.should == false
|
22
|
+
notifier.success_color.should == 'yellow'
|
23
|
+
notifier.warning_color.should == 'yellow'
|
24
|
+
notifier.failure_color.should == 'yellow'
|
25
|
+
|
26
|
+
notifier.on_success.should == true
|
27
|
+
notifier.on_warning.should == true
|
28
|
+
notifier.on_failure.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when setting configuration defaults' do
|
32
|
+
after { Backup::Configuration::Notifier::Hipchat.clear_defaults! }
|
33
|
+
|
34
|
+
it 'should use the configuration defaults' do
|
35
|
+
Backup::Configuration::Notifier::Hipchat.defaults do |notifier|
|
36
|
+
notifier.token = 'old'
|
37
|
+
notifier.from = 'before'
|
38
|
+
notifier.success_color = 'green'
|
39
|
+
|
40
|
+
notifier.on_failure = false
|
41
|
+
end
|
42
|
+
hipchat = Backup::Notifier::Hipchat.new(model)
|
43
|
+
|
44
|
+
hipchat.token.should == 'old'
|
45
|
+
hipchat.from.should == 'before'
|
46
|
+
hipchat.rooms_notified.should == []
|
47
|
+
hipchat.notify_users.should == false
|
48
|
+
hipchat.success_color.should == 'green'
|
49
|
+
hipchat.warning_color.should == 'yellow'
|
50
|
+
hipchat.failure_color.should == 'yellow'
|
51
|
+
|
52
|
+
hipchat.on_success.should == true
|
53
|
+
hipchat.on_warning.should == true
|
54
|
+
hipchat.on_failure.should == false
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should override the configuration defaults' do
|
58
|
+
Backup::Configuration::Notifier::Hipchat.defaults do |notifier|
|
59
|
+
notifier.token = 'old'
|
60
|
+
notifier.from = 'before'
|
61
|
+
notifier.success_color = 'green'
|
62
|
+
|
63
|
+
notifier.on_failure = false
|
64
|
+
end
|
65
|
+
hipchat = Backup::Notifier::Hipchat.new(model) do |notifier|
|
66
|
+
notifier.token = 'new'
|
67
|
+
notifier.from = 'after'
|
68
|
+
notifier.failure_color = 'red'
|
69
|
+
|
70
|
+
notifier.on_success = false
|
71
|
+
notifier.on_failure = true
|
72
|
+
end
|
73
|
+
|
74
|
+
hipchat.token.should == 'new'
|
75
|
+
hipchat.from.should == 'after'
|
76
|
+
hipchat.success_color.should == 'green'
|
77
|
+
hipchat.warning_color.should == 'yellow'
|
78
|
+
hipchat.failure_color.should == 'red'
|
79
|
+
|
80
|
+
hipchat.on_success.should == false
|
81
|
+
hipchat.on_warning.should == true
|
82
|
+
hipchat.on_failure.should == true
|
83
|
+
end
|
84
|
+
end # context 'when setting configuration defaults'
|
85
|
+
|
86
|
+
end # describe '#initialize'
|
87
|
+
|
88
|
+
describe '#notify!' do
|
89
|
+
before do
|
90
|
+
notifier.success_color = 'green'
|
91
|
+
notifier.warning_color = 'yellow'
|
92
|
+
notifier.failure_color = 'red'
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when status is :success' do
|
96
|
+
it 'should send Success message' do
|
97
|
+
notifier.expects(:send_message).with(
|
98
|
+
'[Backup::Success] test label (test_trigger)', 'green'
|
99
|
+
)
|
100
|
+
notifier.send(:notify!, :success)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when status is :warning' do
|
105
|
+
it 'should send Warning message' do
|
106
|
+
notifier.expects(:send_message).with(
|
107
|
+
'[Backup::Warning] test label (test_trigger)', 'yellow'
|
108
|
+
)
|
109
|
+
notifier.send(:notify!, :warning)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when status is :failure' do
|
114
|
+
it 'should send Failure message' do
|
115
|
+
notifier.expects(:send_message).with(
|
116
|
+
'[Backup::Failure] test label (test_trigger)', 'red'
|
117
|
+
)
|
118
|
+
notifier.send(:notify!, :failure)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end # describe '#notify!'
|
122
|
+
|
123
|
+
describe '#send_message' do
|
124
|
+
let(:client) { mock }
|
125
|
+
let(:room) { mock }
|
126
|
+
|
127
|
+
it 'should handle rooms_notified being set as a single room string' do
|
128
|
+
notifier.rooms_notified = 'a_room'
|
129
|
+
HipChat::Client.expects(:new).with('token').returns(client)
|
130
|
+
client.expects(:[]).with('a_room').returns(room)
|
131
|
+
room.expects(:send).with(
|
132
|
+
'application',
|
133
|
+
'a message',
|
134
|
+
{:color => 'a color', :notify => false}
|
135
|
+
)
|
136
|
+
|
137
|
+
notifier.send(:send_message, 'a message', 'a color')
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'when notify_users is set to true' do
|
141
|
+
before { notifier.notify_users = true }
|
142
|
+
|
143
|
+
it 'should notify rooms with :notify => true' do
|
144
|
+
HipChat::Client.expects(:new).with('token').returns(client)
|
145
|
+
|
146
|
+
client.expects(:[]).with('room1').returns(room)
|
147
|
+
room.expects(:send).with(
|
148
|
+
'application',
|
149
|
+
'a message',
|
150
|
+
{:color => 'a color', :notify => true}
|
151
|
+
)
|
152
|
+
|
153
|
+
client.expects(:[]).with('room2').returns(room)
|
154
|
+
room.expects(:send).with(
|
155
|
+
'application',
|
156
|
+
'a message',
|
157
|
+
{:color => 'a color', :notify => true}
|
158
|
+
)
|
159
|
+
|
160
|
+
notifier.send(:send_message, 'a message', 'a color')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'when notify_users is set to false' do
|
165
|
+
before { notifier.notify_users = false }
|
166
|
+
|
167
|
+
it 'should notify rooms with :notify => false' do
|
168
|
+
HipChat::Client.expects(:new).with('token').returns(client)
|
169
|
+
|
170
|
+
client.expects(:[]).with('room1').returns(room)
|
171
|
+
room.expects(:send).with(
|
172
|
+
'application',
|
173
|
+
'a message',
|
174
|
+
{:color => 'a color', :notify => false}
|
175
|
+
)
|
176
|
+
|
177
|
+
client.expects(:[]).with('room2').returns(room)
|
178
|
+
room.expects(:send).with(
|
179
|
+
'application',
|
180
|
+
'a message',
|
181
|
+
{:color => 'a color', :notify => false}
|
182
|
+
)
|
183
|
+
|
184
|
+
notifier.send(:send_message, 'a message', 'a color')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|