backup 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -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 +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -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 +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -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_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -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 +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
@@ -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
|
@@ -3,8 +3,9 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Notifier::Campfire do
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
6
7
|
let(:notifier) do
|
7
|
-
Backup::Notifier::Campfire.new do |campfire|
|
8
|
+
Backup::Notifier::Campfire.new(model) do |campfire|
|
8
9
|
campfire.api_token = 'token'
|
9
10
|
campfire.subdomain = 'subdomain'
|
10
11
|
campfire.room_id = 'room_id'
|
@@ -12,7 +13,7 @@ describe Backup::Notifier::Campfire do
|
|
12
13
|
end
|
13
14
|
|
14
15
|
describe '#initialize' do
|
15
|
-
it 'sets the correct
|
16
|
+
it 'should sets the correct values' do
|
16
17
|
notifier.api_token.should == 'token'
|
17
18
|
notifier.subdomain.should == 'subdomain'
|
18
19
|
notifier.room_id.should == 'room_id'
|
@@ -22,150 +23,177 @@ describe Backup::Notifier::Campfire do
|
|
22
23
|
notifier.on_failure.should == true
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
Backup::Configuration::Notifier::Campfire.
|
27
|
-
campfire.api_token = 'old_token'
|
28
|
-
campfire.on_success = false
|
29
|
-
end
|
30
|
-
notifier = Backup::Notifier::Campfire.new do |campfire|
|
31
|
-
campfire.api_token = 'new_token'
|
32
|
-
end
|
26
|
+
context 'when using configuration defaults' do
|
27
|
+
after { Backup::Configuration::Notifier::Campfire.clear_defaults! }
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
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'
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
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
|
55
48
|
|
56
|
-
|
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'
|
57
54
|
|
58
|
-
|
59
|
-
|
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
|
60
68
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
interface.expects(:base_uri).with(base_uri)
|
65
|
-
interface.expects(:basic_auth).with(notifier.api_token, 'x')
|
66
|
-
message_body = message % 'Success'
|
67
|
-
interface.expects(:post).with(room_url, :body => {
|
68
|
-
:message => { :body => message_body, :type => 'Textmessage' }
|
69
|
-
}.to_json)
|
69
|
+
notifier.api_token.should == 'new_token'
|
70
|
+
notifier.subdomain.should == 'new_subdomain'
|
71
|
+
notifier.room_id.should == 'new_room_id'
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
+
notifier.on_success.should == false
|
74
|
+
notifier.on_warning.should == true
|
75
|
+
notifier.on_failure.should == true
|
73
76
|
end
|
77
|
+
end # context 'when using configuration defaults'
|
78
|
+
end
|
74
79
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
81
89
|
|
82
|
-
|
83
|
-
|
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)
|
84
96
|
end
|
97
|
+
end
|
85
98
|
|
86
|
-
|
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!'
|
87
108
|
|
88
|
-
|
89
|
-
|
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')
|
90
115
|
|
91
|
-
|
92
|
-
|
116
|
+
notifier.send(:send_message, 'a message')
|
117
|
+
end
|
118
|
+
end
|
93
119
|
|
94
|
-
|
95
|
-
notifier.expects(:log!)
|
96
|
-
interface.expects(:room).with(*attrs).returns(room)
|
97
|
-
interface.expects(:base_uri).with(base_uri)
|
98
|
-
interface.expects(:basic_auth).with(notifier.api_token, 'x')
|
99
|
-
message_body = message % 'Warning'
|
100
|
-
interface.expects(:post).with(room_url, :body => {
|
101
|
-
:message => { :body => message_body, :type => 'Textmessage' }
|
102
|
-
}.to_json)
|
120
|
+
end
|
103
121
|
|
104
|
-
|
105
|
-
|
106
|
-
end
|
122
|
+
describe 'Backup::Notifier::Campfire::Interface' do
|
123
|
+
let(:interface) { Backup::Notifier::Campfire::Interface }
|
107
124
|
|
108
|
-
|
109
|
-
|
125
|
+
it 'should include HTTParty' do
|
126
|
+
interface.included_modules.should include(HTTParty)
|
127
|
+
end
|
110
128
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
interface.expects(:base_uri).with(base_uri)
|
115
|
-
interface.expects(:basic_auth).with(notifier.api_token, 'x')
|
116
|
-
message_body = message % 'Warning'
|
117
|
-
interface.expects(:post).with(room_url, :body => {
|
118
|
-
:message => { :body => message_body, :type => 'Textmessage' }
|
119
|
-
}.to_json)
|
129
|
+
it 'should set the proper headers' do
|
130
|
+
interface.headers['Content-Type'].should == 'application/json'
|
131
|
+
end
|
120
132
|
|
121
|
-
|
122
|
-
|
123
|
-
end
|
133
|
+
describe '.room' do
|
134
|
+
let(:room) { mock }
|
124
135
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
notifier.expects(:notify!).never
|
129
|
-
room.expects(:send_message).never
|
130
|
-
interface.expects(:post).never
|
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)
|
131
139
|
|
132
|
-
|
133
|
-
|
134
|
-
|
140
|
+
interface.room('room_id', 'subdomain', 'api_token').should == room
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
135
144
|
|
136
|
-
|
145
|
+
describe 'Backup::Notifier::Campfire::Room' do
|
146
|
+
let(:room) do
|
147
|
+
Backup::Notifier::Campfire::Room.new('room_id', 'subdomain', 'api_token')
|
148
|
+
end
|
137
149
|
|
138
|
-
|
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
|
139
155
|
|
140
|
-
|
141
|
-
|
156
|
+
describe '#message' do
|
157
|
+
it 'should wrap #send_message' do
|
158
|
+
room.expects(:send_message).with('a message')
|
142
159
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
interface.expects(:base_uri).with(base_uri)
|
147
|
-
interface.expects(:basic_auth).with(notifier.api_token, 'x')
|
148
|
-
message_body = message % 'Failure'
|
149
|
-
interface.expects(:post).with(room_url, :body => {
|
150
|
-
:message => { :body => message_body, :type => 'Textmessage' }
|
151
|
-
}.to_json)
|
160
|
+
room.message('a message')
|
161
|
+
end
|
162
|
+
end
|
152
163
|
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
156
179
|
|
157
|
-
|
158
|
-
|
159
|
-
notifier.expects(:log!).never
|
160
|
-
notifier.expects(:notify!).never
|
161
|
-
room.expects(:send_message).never
|
162
|
-
interface.expects(:post).never
|
180
|
+
describe '#post' do
|
181
|
+
let(:interface) { Backup::Notifier::Campfire::Interface }
|
163
182
|
|
164
|
-
|
165
|
-
|
166
|
-
|
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' })
|
167
188
|
|
168
|
-
|
189
|
+
room.send(:post, 'an_action', :hash => 'of options')
|
190
|
+
end
|
191
|
+
end
|
169
192
|
|
170
|
-
|
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
|
171
199
|
end
|
@@ -3,191 +3,186 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Notifier::Hipchat do
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
6
7
|
let(:notifier) do
|
7
|
-
Backup::Notifier::Hipchat.new do |notifier|
|
8
|
-
notifier.from = 'application'
|
8
|
+
Backup::Notifier::Hipchat.new(model) do |notifier|
|
9
9
|
notifier.token = 'token'
|
10
|
+
notifier.from = 'application'
|
10
11
|
notifier.rooms_notified = ['room1', 'room2']
|
11
|
-
notifier.notify_users = true
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '#initialize' do
|
16
16
|
|
17
|
-
it
|
18
|
-
notifier.
|
19
|
-
notifier.
|
20
|
-
notifier.
|
21
|
-
notifier.
|
22
|
-
notifier.
|
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
|
+
|
23
26
|
notifier.on_success.should == true
|
24
27
|
notifier.on_warning.should == true
|
25
28
|
notifier.on_failure.should == true
|
26
29
|
end
|
27
30
|
|
28
|
-
|
29
|
-
Backup::Configuration::Notifier::Hipchat.
|
30
|
-
notifier.token = 'old'
|
31
|
-
notifier.from = 'before'
|
32
|
-
notifier.success_color = 'green'
|
33
|
-
end
|
34
|
-
hipchat = Backup::Notifier::Hipchat.new do |notifier|
|
35
|
-
notifier.token = 'new'
|
36
|
-
notifier.from = 'after'
|
37
|
-
notifier.failure_color = 'red'
|
38
|
-
end
|
39
|
-
|
40
|
-
hipchat.token.should == 'new'
|
41
|
-
hipchat.from.should == 'after'
|
42
|
-
hipchat.success_color.should == 'green'
|
43
|
-
hipchat.warning_color.should == 'yellow'
|
44
|
-
hipchat.failure_color.should == 'red'
|
45
|
-
hipchat.on_success.should == true
|
46
|
-
hipchat.on_warning.should == true
|
47
|
-
hipchat.on_failure.should == true
|
48
|
-
end
|
49
|
-
|
50
|
-
end # describe '#initialize'
|
51
|
-
|
52
|
-
describe '#perform!' do
|
53
|
-
let(:model) { Backup::Model.new('trigger', 'label') {} }
|
54
|
-
let(:hipchat_mock) { mock }
|
55
|
-
let(:hipchat_client) { HipChat::Client.any_instance }
|
56
|
-
let(:message) { '[Backup::%s] label (trigger)' }
|
57
|
-
|
58
|
-
before do
|
59
|
-
notifier.on_success = false
|
60
|
-
notifier.on_warning = false
|
61
|
-
notifier.on_failure = false
|
62
|
-
notifier.success_color = 'green'
|
63
|
-
notifier.warning_color = 'yellow'
|
64
|
-
notifier.failure_color = 'red'
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'success' do
|
31
|
+
context 'when setting configuration defaults' do
|
32
|
+
after { Backup::Configuration::Notifier::Hipchat.clear_defaults! }
|
68
33
|
|
69
|
-
|
70
|
-
|
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'
|
71
39
|
|
72
|
-
|
73
|
-
notifier.expects(:log!)
|
74
|
-
hipchat_client.expects(:[]).with('room1').returns(hipchat_mock)
|
75
|
-
hipchat_client.expects(:[]).with('room2').returns(hipchat_mock)
|
76
|
-
hipchat_mock.expects(:send).twice.with {|user, msg, hash|
|
77
|
-
(user.should == notifier.from) &&
|
78
|
-
(msg.should == message % 'Success') &&
|
79
|
-
(hash[:color].should == notifier.success_color) &&
|
80
|
-
(hash[:notify].should == notifier.notify_users)
|
81
|
-
}
|
82
|
-
|
83
|
-
notifier.perform!(model)
|
40
|
+
notifier.on_failure = false
|
84
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
|
85
55
|
end
|
86
56
|
|
87
|
-
|
88
|
-
|
89
|
-
notifier.
|
90
|
-
notifier.
|
91
|
-
|
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'
|
92
62
|
|
93
|
-
notifier.
|
63
|
+
notifier.on_failure = false
|
94
64
|
end
|
95
|
-
|
65
|
+
hipchat = Backup::Notifier::Hipchat.new(model) do |notifier|
|
66
|
+
notifier.token = 'new'
|
67
|
+
notifier.from = 'after'
|
68
|
+
notifier.failure_color = 'red'
|
96
69
|
|
97
|
-
|
70
|
+
notifier.on_success = false
|
71
|
+
notifier.on_failure = true
|
72
|
+
end
|
98
73
|
|
99
|
-
|
100
|
-
|
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'
|
101
85
|
|
102
|
-
|
103
|
-
before { notifier.on_success = true }
|
86
|
+
end # describe '#initialize'
|
104
87
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
(msg.should == message % 'Warning') &&
|
112
|
-
(hash[:color].should == notifier.warning_color) &&
|
113
|
-
(hash[:notify].should == notifier.notify_users)
|
114
|
-
}
|
88
|
+
describe '#notify!' do
|
89
|
+
before do
|
90
|
+
notifier.success_color = 'green'
|
91
|
+
notifier.warning_color = 'yellow'
|
92
|
+
notifier.failure_color = 'red'
|
93
|
+
end
|
115
94
|
|
116
|
-
|
117
|
-
|
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)
|
118
101
|
end
|
102
|
+
end
|
119
103
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
hipchat_client.expects(:[]).with('room2').returns(hipchat_mock)
|
127
|
-
hipchat_mock.expects(:send).twice.with {|user, msg, hash|
|
128
|
-
(user.should == notifier.from) &&
|
129
|
-
(msg.should == message % 'Warning') &&
|
130
|
-
(hash[:color].should == notifier.warning_color) &&
|
131
|
-
(hash[:notify].should == notifier.notify_users)
|
132
|
-
}
|
133
|
-
|
134
|
-
notifier.perform!(model)
|
135
|
-
end
|
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)
|
136
110
|
end
|
111
|
+
end
|
137
112
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
notifier.perform!(model)
|
145
|
-
end
|
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)
|
146
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
|
147
139
|
|
148
|
-
|
140
|
+
context 'when notify_users is set to true' do
|
141
|
+
before { notifier.notify_users = true }
|
149
142
|
|
150
|
-
|
143
|
+
it 'should notify rooms with :notify => true' do
|
144
|
+
HipChat::Client.expects(:new).with('token').returns(client)
|
151
145
|
|
152
|
-
|
153
|
-
|
146
|
+
client.expects(:[]).with('room1').returns(room)
|
147
|
+
room.expects(:send).with(
|
148
|
+
'application',
|
149
|
+
'a message',
|
150
|
+
{:color => 'a color', :notify => true}
|
151
|
+
)
|
154
152
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
(msg.should == message % 'Failure') &&
|
162
|
-
(hash[:color].should == notifier.failure_color) &&
|
163
|
-
(hash[:notify].should == notifier.notify_users)
|
164
|
-
}
|
153
|
+
client.expects(:[]).with('room2').returns(room)
|
154
|
+
room.expects(:send).with(
|
155
|
+
'application',
|
156
|
+
'a message',
|
157
|
+
{:color => 'a color', :notify => true}
|
158
|
+
)
|
165
159
|
|
166
|
-
|
167
|
-
end
|
160
|
+
notifier.send(:send_message, 'a message', 'a color')
|
168
161
|
end
|
162
|
+
end
|
169
163
|
|
170
|
-
|
171
|
-
|
172
|
-
notifier.expects(:log!).never
|
173
|
-
notifier.expects(:notify!).never
|
174
|
-
hipchat_client.expects(:[]).never
|
164
|
+
context 'when notify_users is set to false' do
|
165
|
+
before { notifier.notify_users = false }
|
175
166
|
|
176
|
-
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
end # context 'failure'
|
167
|
+
it 'should notify rooms with :notify => false' do
|
168
|
+
HipChat::Client.expects(:new).with('token').returns(client)
|
181
169
|
|
182
|
-
|
183
|
-
|
184
|
-
|
170
|
+
client.expects(:[]).with('room1').returns(room)
|
171
|
+
room.expects(:send).with(
|
172
|
+
'application',
|
173
|
+
'a message',
|
174
|
+
{:color => 'a color', :notify => false}
|
175
|
+
)
|
185
176
|
|
186
|
-
|
177
|
+
client.expects(:[]).with('room2').returns(room)
|
178
|
+
room.expects(:send).with(
|
179
|
+
'application',
|
180
|
+
'a message',
|
181
|
+
{:color => 'a color', :notify => false}
|
182
|
+
)
|
187
183
|
|
188
|
-
|
189
|
-
|
184
|
+
notifier.send(:send_message, 'a message', 'a color')
|
185
|
+
end
|
190
186
|
end
|
191
|
-
|
192
|
-
end # describe '#perform!'
|
187
|
+
end
|
193
188
|
end
|