backup 3.0.19 → 3.0.20
Sign up to get free protection for your applications and to get access to all the features.
- 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,6 +1,6 @@
|
|
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::Campfire do
|
6
6
|
let(:notifier) do
|
@@ -11,21 +11,21 @@ describe Backup::Notifier::Campfire do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
describe '#initialize' do
|
15
|
+
it 'sets the correct defaults' do
|
16
|
+
notifier.api_token.should == 'token'
|
17
|
+
notifier.subdomain.should == 'subdomain'
|
18
|
+
notifier.room_id.should == 'room_id'
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
notifier.on_success.should == true
|
21
|
+
notifier.on_warning.should == true
|
22
|
+
notifier.on_failure.should == true
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
it do
|
25
|
+
it 'uses and overrides configuration defaults' do
|
25
26
|
Backup::Configuration::Notifier::Campfire.defaults do |campfire|
|
26
27
|
campfire.api_token = 'old_token'
|
27
28
|
campfire.on_success = false
|
28
|
-
campfire.on_failure = true
|
29
29
|
end
|
30
30
|
notifier = Backup::Notifier::Campfire.new do |campfire|
|
31
31
|
campfire.api_token = 'new_token'
|
@@ -33,64 +33,139 @@ describe Backup::Notifier::Campfire do
|
|
33
33
|
|
34
34
|
notifier.api_token.should == 'new_token'
|
35
35
|
notifier.on_success.should == false
|
36
|
+
notifier.on_warning.should == true
|
36
37
|
notifier.on_failure.should == true
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
describe '#initialize' do
|
41
|
-
it do
|
42
|
-
Backup::Notifier::Campfire.any_instance.expects(:set_defaults!)
|
43
|
-
Backup::Notifier::Campfire.new
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
41
|
describe '#perform!' do
|
48
|
-
let(:model)
|
42
|
+
let(:model) { Backup::Model.new('trigger', 'label') {} }
|
43
|
+
let(:interface) { Backup::Notifier::Campfire::Interface }
|
44
|
+
let(:attrs) { [notifier.room_id, notifier.subdomain, notifier.api_token] }
|
45
|
+
let(:room) { Backup::Notifier::Campfire::Room.new(*attrs) }
|
46
|
+
let(:base_uri) { "https://#{notifier.subdomain}.campfirenow.com" }
|
47
|
+
let(:room_url) { "/room/#{notifier.room_id}/speak.json" }
|
48
|
+
let(:message) { '[Backup::%s] label (trigger)' }
|
49
|
+
|
49
50
|
before do
|
50
51
|
notifier.on_success = false
|
52
|
+
notifier.on_warning = false
|
51
53
|
notifier.on_failure = false
|
52
54
|
end
|
53
55
|
|
54
|
-
context
|
55
|
-
|
56
|
-
|
57
|
-
notifier.
|
58
|
-
|
59
|
-
|
56
|
+
context 'success' do
|
57
|
+
|
58
|
+
context 'when on_success is true' do
|
59
|
+
before { notifier.on_success = true }
|
60
|
+
|
61
|
+
it 'sends success message' do
|
62
|
+
notifier.expects(:log!)
|
63
|
+
interface.expects(:room).with(*attrs).returns(room)
|
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)
|
70
|
+
|
71
|
+
notifier.perform!(model)
|
72
|
+
end
|
60
73
|
end
|
61
74
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
75
|
+
context 'when on_success is false' do
|
76
|
+
it 'sends no message' do
|
77
|
+
notifier.expects(:log!).never
|
78
|
+
notifier.expects(:notify!).never
|
79
|
+
room.expects(:send_message).never
|
80
|
+
interface.expects(:post).never
|
81
|
+
|
82
|
+
notifier.perform!(model)
|
83
|
+
end
|
66
84
|
end
|
67
|
-
end
|
68
85
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
86
|
+
end # context 'success'
|
87
|
+
|
88
|
+
context 'warning' do
|
89
|
+
before { Backup::Logger.stubs(:has_warnings?).returns(true) }
|
90
|
+
|
91
|
+
context 'when on_success is true' do
|
92
|
+
before { notifier.on_success = true }
|
93
|
+
|
94
|
+
it 'sends warning message' do
|
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)
|
103
|
+
|
104
|
+
notifier.perform!(model)
|
105
|
+
end
|
75
106
|
end
|
76
107
|
|
77
|
-
|
78
|
-
notifier.
|
79
|
-
|
80
|
-
|
108
|
+
context 'when on_warning is true' do
|
109
|
+
before { notifier.on_warning = true }
|
110
|
+
|
111
|
+
it 'sends warning message' do
|
112
|
+
notifier.expects(:log!)
|
113
|
+
interface.expects(:room).with(*attrs).returns(room)
|
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)
|
120
|
+
|
121
|
+
notifier.perform!(model)
|
122
|
+
end
|
81
123
|
end
|
82
|
-
end
|
83
|
-
end
|
84
124
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
125
|
+
context 'when on_success and on_warning are false' do
|
126
|
+
it 'sends no message' do
|
127
|
+
notifier.expects(:log!).never
|
128
|
+
notifier.expects(:notify!).never
|
129
|
+
room.expects(:send_message).never
|
130
|
+
interface.expects(:post).never
|
89
131
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
|
132
|
+
notifier.perform!(model)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end # context 'warning'
|
137
|
+
|
138
|
+
context 'failure' do
|
139
|
+
|
140
|
+
context 'when on_failure is true' do
|
141
|
+
before { notifier.on_failure = true }
|
142
|
+
|
143
|
+
it 'sends failure message' do
|
144
|
+
notifier.expects(:log!)
|
145
|
+
interface.expects(:room).with(*attrs).returns(room)
|
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)
|
152
|
+
|
153
|
+
notifier.perform!(model, Exception.new)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when on_failure is false' do
|
158
|
+
it 'sends no message' do
|
159
|
+
notifier.expects(:log!).never
|
160
|
+
notifier.expects(:notify!).never
|
161
|
+
room.expects(:send_message).never
|
162
|
+
interface.expects(:post).never
|
163
|
+
|
164
|
+
notifier.perform!(model, Exception.new)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end # context 'failure'
|
169
|
+
|
170
|
+
end # describe '#perform!'
|
96
171
|
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Notifier::Hipchat do
|
6
|
+
let(:notifier) do
|
7
|
+
Backup::Notifier::Hipchat.new do |notifier|
|
8
|
+
notifier.from = 'application'
|
9
|
+
notifier.token = 'token'
|
10
|
+
notifier.rooms_notified = ['room1', 'room2']
|
11
|
+
notifier.notify_users = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#initialize' do
|
16
|
+
|
17
|
+
it "sets the correct defaults" do
|
18
|
+
notifier.from.should == 'application'
|
19
|
+
notifier.token.should == 'token'
|
20
|
+
notifier.success_color.should == 'yellow'
|
21
|
+
notifier.warning_color.should == 'yellow'
|
22
|
+
notifier.failure_color.should == 'yellow'
|
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::Hipchat.defaults do |notifier|
|
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
|
68
|
+
|
69
|
+
context 'when on_success is true' do
|
70
|
+
before { notifier.on_success = true }
|
71
|
+
|
72
|
+
it 'sends success message' do
|
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)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when on_success is false' do
|
88
|
+
it 'sends no message' do
|
89
|
+
notifier.expects(:log!).never
|
90
|
+
notifier.expects(:notify!).never
|
91
|
+
hipchat_client.expects(:[]).never
|
92
|
+
|
93
|
+
notifier.perform!(model)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end # context 'success'
|
98
|
+
|
99
|
+
context 'warning' do
|
100
|
+
before { Backup::Logger.stubs(:has_warnings?).returns(true) }
|
101
|
+
|
102
|
+
context 'when on_success is true' do
|
103
|
+
before { notifier.on_success = true }
|
104
|
+
|
105
|
+
it 'sends warning message' do
|
106
|
+
notifier.expects(:log!)
|
107
|
+
hipchat_client.expects(:[]).with('room1').returns(hipchat_mock)
|
108
|
+
hipchat_client.expects(:[]).with('room2').returns(hipchat_mock)
|
109
|
+
hipchat_mock.expects(:send).twice.with {|user, msg, hash|
|
110
|
+
(user.should == notifier.from) &&
|
111
|
+
(msg.should == message % 'Warning') &&
|
112
|
+
(hash[:color].should == notifier.warning_color) &&
|
113
|
+
(hash[:notify].should == notifier.notify_users)
|
114
|
+
}
|
115
|
+
|
116
|
+
notifier.perform!(model)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when on_warning is true' do
|
121
|
+
before { notifier.on_warning = true }
|
122
|
+
|
123
|
+
it 'sends warning message' do
|
124
|
+
notifier.expects(:log!)
|
125
|
+
hipchat_client.expects(:[]).with('room1').returns(hipchat_mock)
|
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
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'when on_success and on_warning are false' do
|
139
|
+
it 'sends no message' do
|
140
|
+
notifier.expects(:log!).never
|
141
|
+
notifier.expects(:notify!).never
|
142
|
+
hipchat_client.expects(:[]).never
|
143
|
+
|
144
|
+
notifier.perform!(model)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end # context 'warning'
|
149
|
+
|
150
|
+
context 'failure' do
|
151
|
+
|
152
|
+
context 'when on_failure is true' do
|
153
|
+
before { notifier.on_failure = true }
|
154
|
+
|
155
|
+
it 'sends failure message' do
|
156
|
+
notifier.expects(:log!)
|
157
|
+
hipchat_client.expects(:[]).with('room1').returns(hipchat_mock)
|
158
|
+
hipchat_client.expects(:[]).with('room2').returns(hipchat_mock)
|
159
|
+
hipchat_mock.expects(:send).twice.with {|user, msg, hash|
|
160
|
+
(user.should == notifier.from) &&
|
161
|
+
(msg.should == message % 'Failure') &&
|
162
|
+
(hash[:color].should == notifier.failure_color) &&
|
163
|
+
(hash[:notify].should == notifier.notify_users)
|
164
|
+
}
|
165
|
+
|
166
|
+
notifier.perform!(model, Exception.new)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when on_failure is false' do
|
171
|
+
it 'sends no message' do
|
172
|
+
notifier.expects(:log!).never
|
173
|
+
notifier.expects(:notify!).never
|
174
|
+
hipchat_client.expects(:[]).never
|
175
|
+
|
176
|
+
notifier.perform!(model, Exception.new)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
end # context 'failure'
|
181
|
+
|
182
|
+
it 'will convert a single room param to an array' do
|
183
|
+
notifier.on_success = true
|
184
|
+
notifier.rooms_notified = 'one_room'
|
185
|
+
|
186
|
+
hipchat_client.expects(:[]).with('one_room').returns(stub(:send))
|
187
|
+
|
188
|
+
notifier.perform!(model)
|
189
|
+
notifier.rooms_notified.should == ['one_room']
|
190
|
+
end
|
191
|
+
|
192
|
+
end # describe '#perform!'
|
193
|
+
end
|
data/spec/notifier/mail_spec.rb
CHANGED
@@ -1,97 +1,313 @@
|
|
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::Mail do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
|
9
|
+
context 'specifying the delivery_method' do
|
10
|
+
|
11
|
+
it 'creates a new notifier using Mail::SMTP' do
|
12
|
+
notifier = Backup::Notifier::Mail.new do |mail|
|
13
|
+
mail.delivery_method = :smtp
|
14
|
+
mail.from = 'my.sender.email@gmail.com'
|
15
|
+
mail.to = 'my.receiver.email@gmail.com'
|
16
|
+
mail.address = 'smtp.gmail.com'
|
17
|
+
mail.port = 587
|
18
|
+
mail.domain = 'your.host.name'
|
19
|
+
mail.user_name = 'user'
|
20
|
+
mail.password = 'secret'
|
21
|
+
mail.authentication = 'plain'
|
22
|
+
mail.enable_starttls_auto = true
|
23
|
+
end
|
24
|
+
|
25
|
+
notifier.mail.delivery_method.should
|
26
|
+
be_an_instance_of ::Mail::SMTP
|
27
|
+
|
28
|
+
notifier.delivery_method.should == 'smtp'
|
29
|
+
notifier.from.should == 'my.sender.email@gmail.com'
|
30
|
+
notifier.to.should == 'my.receiver.email@gmail.com'
|
31
|
+
notifier.address.should == 'smtp.gmail.com'
|
32
|
+
notifier.port.should == 587
|
33
|
+
notifier.domain.should == 'your.host.name'
|
34
|
+
notifier.user_name.should == 'user'
|
35
|
+
notifier.password.should == 'secret'
|
36
|
+
notifier.authentication.should == 'plain'
|
37
|
+
notifier.enable_starttls_auto.should == true
|
38
|
+
notifier.openssl_verify_mode.should be_nil
|
39
|
+
notifier.sendmail.should be_nil
|
40
|
+
notifier.sendmail_args.should be_nil
|
41
|
+
notifier.mail_folder.should be_nil
|
42
|
+
|
43
|
+
notifier.on_success.should == true
|
44
|
+
notifier.on_warning.should == true
|
45
|
+
notifier.on_failure.should == true
|
41
46
|
end
|
42
|
-
|
43
|
-
|
47
|
+
|
48
|
+
it 'creates a new notifier using Mail::Sendmail' do
|
49
|
+
notifier = Backup::Notifier::Mail.new do |mail|
|
50
|
+
mail.delivery_method = :sendmail
|
51
|
+
mail.from = 'my.sender.email@gmail.com'
|
52
|
+
mail.to = 'my.receiver.email@gmail.com'
|
53
|
+
mail.sendmail = '/path/to/sendmail'
|
54
|
+
mail.sendmail_args = '-i -t -X/tmp/traffic.log'
|
55
|
+
end
|
56
|
+
|
57
|
+
notifier.mail.delivery_method.should
|
58
|
+
be_an_instance_of ::Mail::Sendmail
|
59
|
+
|
60
|
+
notifier.delivery_method.should == 'sendmail'
|
61
|
+
notifier.from.should == 'my.sender.email@gmail.com'
|
62
|
+
notifier.to.should == 'my.receiver.email@gmail.com'
|
63
|
+
notifier.address.should be_nil
|
64
|
+
notifier.port.should be_nil
|
65
|
+
notifier.domain.should be_nil
|
66
|
+
notifier.user_name.should be_nil
|
67
|
+
notifier.password.should be_nil
|
68
|
+
notifier.authentication.should be_nil
|
69
|
+
notifier.enable_starttls_auto.should be_nil
|
70
|
+
notifier.openssl_verify_mode.should be_nil
|
71
|
+
notifier.sendmail.should == '/path/to/sendmail'
|
72
|
+
notifier.sendmail_args.should == '-i -t -X/tmp/traffic.log'
|
73
|
+
notifier.mail_folder.should be_nil
|
74
|
+
|
75
|
+
notifier.on_success.should == true
|
76
|
+
notifier.on_warning.should == true
|
77
|
+
notifier.on_failure.should == true
|
44
78
|
end
|
45
79
|
|
46
|
-
notifier
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
80
|
+
it 'creates a new notifier using Mail::FileDelivery' do
|
81
|
+
notifier = Backup::Notifier::Mail.new do |mail|
|
82
|
+
mail.delivery_method = :file
|
83
|
+
mail.from = 'my.sender.email@gmail.com'
|
84
|
+
mail.to = 'my.receiver.email@gmail.com'
|
85
|
+
mail.mail_folder = '/path/to/backup/mails'
|
86
|
+
end
|
52
87
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
88
|
+
notifier.mail.delivery_method.should
|
89
|
+
be_an_instance_of ::Mail::FileDelivery
|
90
|
+
|
91
|
+
notifier.delivery_method.should == 'file'
|
92
|
+
notifier.from.should == 'my.sender.email@gmail.com'
|
93
|
+
notifier.to.should == 'my.receiver.email@gmail.com'
|
94
|
+
notifier.address.should be_nil
|
95
|
+
notifier.port.should be_nil
|
96
|
+
notifier.domain.should be_nil
|
97
|
+
notifier.user_name.should be_nil
|
98
|
+
notifier.password.should be_nil
|
99
|
+
notifier.authentication.should be_nil
|
100
|
+
notifier.enable_starttls_auto.should be_nil
|
101
|
+
notifier.openssl_verify_mode.should be_nil
|
102
|
+
notifier.sendmail.should be_nil
|
103
|
+
notifier.sendmail_args.should be_nil
|
104
|
+
notifier.mail_folder.should == '/path/to/backup/mails'
|
105
|
+
|
106
|
+
notifier.on_success.should == true
|
107
|
+
notifier.on_warning.should == true
|
108
|
+
notifier.on_failure.should == true
|
109
|
+
end
|
110
|
+
|
111
|
+
end # context 'specifying the delivery_method'
|
112
|
+
|
113
|
+
context 'without specifying the delivery_method' do
|
114
|
+
|
115
|
+
it 'uses Mail::SMTP by default' do
|
116
|
+
[nil, :foo, 'foo'].each do |val|
|
117
|
+
notifier = Backup::Notifier::Mail.new do |mail|
|
118
|
+
mail.delivery_method = val
|
119
|
+
mail.from = 'my.sender.email@gmail.com'
|
120
|
+
mail.to = 'my.receiver.email@gmail.com'
|
121
|
+
end
|
122
|
+
|
123
|
+
notifier.delivery_method.should == 'smtp'
|
124
|
+
notifier.from.should == 'my.sender.email@gmail.com'
|
125
|
+
notifier.to.should == 'my.receiver.email@gmail.com'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end # context 'without specifying the delivery_method'
|
130
|
+
|
131
|
+
describe 'setting configuration defaults' do
|
132
|
+
let(:config) { Backup::Configuration::Notifier::Mail }
|
133
|
+
after { config.clear_defaults! }
|
134
|
+
|
135
|
+
it 'uses and overrides configuration defaults' do
|
136
|
+
config.defaults do |mail|
|
137
|
+
mail.delivery_method = :file
|
138
|
+
mail.to = 'some.receiver.email@gmail.com'
|
139
|
+
mail.from = 'default.sender.email@gmail.com'
|
140
|
+
mail.on_success = false
|
141
|
+
end
|
142
|
+
|
143
|
+
config.delivery_method.should == :file
|
144
|
+
config.to.should == 'some.receiver.email@gmail.com'
|
145
|
+
config.from.should == 'default.sender.email@gmail.com'
|
146
|
+
config.on_success.should == false
|
147
|
+
|
148
|
+
notifier = Backup::Notifier::Mail.new do |mail|
|
149
|
+
mail.mail_folder = '/my/backup/mails'
|
150
|
+
mail.from = 'my.sender.email@gmail.com'
|
151
|
+
mail.on_warning = false
|
152
|
+
end
|
153
|
+
|
154
|
+
notifier.delivery_method.should == 'file'
|
155
|
+
notifier.mail_folder = '/my/backup/mails'
|
156
|
+
notifier.to.should == 'some.receiver.email@gmail.com'
|
157
|
+
notifier.from.should == 'my.sender.email@gmail.com'
|
158
|
+
|
159
|
+
notifier.on_success.should == false
|
160
|
+
notifier.on_warning.should == false
|
161
|
+
notifier.on_failure.should == true
|
162
|
+
end
|
163
|
+
|
164
|
+
end # describe 'setting configuration defaults'
|
165
|
+
|
166
|
+
end # describe '#initialize'
|
59
167
|
|
60
168
|
describe '#perform!' do
|
61
|
-
let(:model) { Backup::Model.new('
|
169
|
+
let(:model) { Backup::Model.new('trigger', 'label') {} }
|
170
|
+
let(:message) { '[Backup::%s] label (trigger)' }
|
171
|
+
let(:notifier) do
|
172
|
+
Backup::Notifier::Mail.new do |mail|
|
173
|
+
mail.delivery_method = :test
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
62
177
|
before do
|
63
178
|
notifier.on_success = false
|
179
|
+
notifier.on_warning = false
|
64
180
|
notifier.on_failure = false
|
181
|
+
::Mail::TestMailer.deliveries.clear
|
65
182
|
end
|
66
183
|
|
67
|
-
context
|
68
|
-
|
69
|
-
|
70
|
-
notifier.
|
71
|
-
|
72
|
-
|
184
|
+
context 'success' do
|
185
|
+
|
186
|
+
context 'when Notifier#on_success is true' do
|
187
|
+
before { notifier.on_success = true }
|
188
|
+
|
189
|
+
it 'sends the notification without an attached backup log' do
|
190
|
+
notifier.expects(:log!)
|
191
|
+
Backup::Template.any_instance.expects(:result).
|
192
|
+
with('notifier/mail/success.erb').
|
193
|
+
returns('message body')
|
194
|
+
|
195
|
+
notifier.perform!(model)
|
196
|
+
sent_message = ::Mail::TestMailer.deliveries.first
|
197
|
+
sent_message.subject.should == message % 'Success'
|
198
|
+
sent_message.multipart?.should be_false
|
199
|
+
sent_message.body.should == 'message body'
|
200
|
+
sent_message.has_attachments?.should be_false
|
201
|
+
end
|
73
202
|
end
|
74
203
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
204
|
+
context 'when Notifier#on_success is false' do
|
205
|
+
it 'does not send the notification' do
|
206
|
+
notifier.expects(:log!).never
|
207
|
+
notifier.expects(:notify!).never
|
208
|
+
|
209
|
+
notifier.perform!(model)
|
210
|
+
::Mail::TestMailer.deliveries.should be_empty
|
211
|
+
end
|
79
212
|
end
|
80
|
-
end
|
81
213
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
214
|
+
end # context 'success'
|
215
|
+
|
216
|
+
context 'warning' do
|
217
|
+
let(:log_messages){ ['line 1', 'line 2', 'line 3'] }
|
218
|
+
|
219
|
+
before do
|
220
|
+
Backup::Logger.stubs(:has_warnings?).returns(true)
|
221
|
+
Backup::Logger.stubs(:messages).returns(log_messages)
|
88
222
|
end
|
89
223
|
|
90
|
-
|
91
|
-
notifier.
|
92
|
-
|
93
|
-
|
224
|
+
context 'when Notifier#on_warning is true' do
|
225
|
+
before { notifier.on_warning = true }
|
226
|
+
|
227
|
+
it 'sends the notification with an attached backup log' do
|
228
|
+
notifier.expects(:log!)
|
229
|
+
Backup::Template.any_instance.expects(:result).
|
230
|
+
with('notifier/mail/warning.erb').
|
231
|
+
returns('message body')
|
232
|
+
|
233
|
+
notifier.perform!(model)
|
234
|
+
sent_message = ::Mail::TestMailer.deliveries.first
|
235
|
+
sent_message.subject.should == message % 'Warning'
|
236
|
+
sent_message.body.multipart?.should be_true
|
237
|
+
sent_message.text_part.decoded.should == 'message body'
|
238
|
+
sent_message.attachments["#{model.time}.#{model.trigger}.log"].
|
239
|
+
read.should == "line 1\nline 2\nline 3"
|
240
|
+
end
|
94
241
|
end
|
95
|
-
|
96
|
-
|
242
|
+
|
243
|
+
context 'when Notifier#on_success is true' do
|
244
|
+
before { notifier.on_success = true }
|
245
|
+
|
246
|
+
it 'sends the notification with an attched backup log' do
|
247
|
+
notifier.expects(:log!)
|
248
|
+
Backup::Template.any_instance.expects(:result).
|
249
|
+
with('notifier/mail/warning.erb').
|
250
|
+
returns('message body')
|
251
|
+
|
252
|
+
notifier.perform!(model)
|
253
|
+
sent_message = ::Mail::TestMailer.deliveries.first
|
254
|
+
sent_message.subject.should == message % 'Warning'
|
255
|
+
sent_message.body.multipart?.should be_true
|
256
|
+
sent_message.text_part.decoded.should == 'message body'
|
257
|
+
sent_message.attachments["#{model.time}.#{model.trigger}.log"].
|
258
|
+
read.should == "line 1\nline 2\nline 3"
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'when Notifier#on_warning and Notifier#on_success are false' do
|
263
|
+
it 'does not send the notification' do
|
264
|
+
notifier.expects(:log!).never
|
265
|
+
notifier.expects(:notify!).never
|
266
|
+
|
267
|
+
notifier.perform!(model)
|
268
|
+
::Mail::TestMailer.deliveries.should be_empty
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
end # context 'warning'
|
273
|
+
|
274
|
+
context 'failure' do
|
275
|
+
let(:log_messages){ ['line 1', 'line 2', 'line 3'] }
|
276
|
+
|
277
|
+
before do
|
278
|
+
Backup::Logger.stubs(:messages).returns(log_messages)
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'when Notifier#on_failure is true' do
|
282
|
+
before { notifier.on_failure = true }
|
283
|
+
|
284
|
+
it 'sends the notification with an attached backup log' do
|
285
|
+
notifier.expects(:log!)
|
286
|
+
Backup::Template.any_instance.expects(:result).
|
287
|
+
with('notifier/mail/failure.erb').
|
288
|
+
returns('message body')
|
289
|
+
|
290
|
+
notifier.perform!(model, Exception.new)
|
291
|
+
sent_message = ::Mail::TestMailer.deliveries.first
|
292
|
+
sent_message.subject.should == message % 'Failure'
|
293
|
+
sent_message.body.multipart?.should be_true
|
294
|
+
sent_message.text_part.decoded.should == 'message body'
|
295
|
+
sent_message.attachments["#{model.time}.#{model.trigger}.log"].
|
296
|
+
read.should == "line 1\nline 2\nline 3"
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
context 'when Notifier#on_failure is false' do
|
301
|
+
it 'does not send the notification' do
|
302
|
+
notifier.expects(:log!).never
|
303
|
+
notifier.expects(:notify!).never
|
304
|
+
|
305
|
+
notifier.perform!(model, Exception.new)
|
306
|
+
::Mail::TestMailer.deliveries.should be_empty
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
end # context 'failure'
|
311
|
+
|
312
|
+
end # describe '#perform!'
|
97
313
|
end
|