cerberus 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/CHANGES +159 -129
  2. data/LICENSE +21 -21
  3. data/README +75 -75
  4. data/Rakefile +161 -159
  5. data/bin/cerberus +2 -2
  6. data/lib/cerberus/builder/maven2.rb +38 -38
  7. data/lib/cerberus/builder/rake.rb +7 -7
  8. data/lib/cerberus/builder/rant.rb +7 -7
  9. data/lib/cerberus/builder/rspec.rb +13 -0
  10. data/lib/cerberus/builder/ruby_base.rb +48 -47
  11. data/lib/cerberus/cli.rb +73 -70
  12. data/lib/cerberus/component_lazy_loader.rb +2 -0
  13. data/lib/cerberus/config.example.yml +28 -28
  14. data/lib/cerberus/config.rb +47 -46
  15. data/lib/cerberus/constants.rb +8 -8
  16. data/lib/cerberus/latch.rb +26 -26
  17. data/lib/cerberus/manager.rb +296 -267
  18. data/lib/cerberus/publisher/base.rb +47 -47
  19. data/lib/cerberus/publisher/gmailer.rb +17 -0
  20. data/lib/cerberus/publisher/irc.rb +27 -27
  21. data/lib/cerberus/publisher/jabber.rb +25 -25
  22. data/lib/cerberus/publisher/mail.rb +36 -36
  23. data/lib/cerberus/publisher/netsmtp_tls_fix.rb +66 -66
  24. data/lib/cerberus/publisher/rss.rb +27 -28
  25. data/lib/cerberus/scm/cvs.rb +48 -48
  26. data/lib/cerberus/scm/darcs.rb +70 -70
  27. data/lib/cerberus/scm/svn.rb +83 -83
  28. data/lib/cerberus/utils.rb +156 -156
  29. data/test/config_test.rb +45 -45
  30. data/test/functional_test.rb +288 -287
  31. data/test/integration_test.rb +104 -104
  32. data/test/irc_publisher_test.rb +18 -18
  33. data/test/jabber_publisher_test.rb +21 -21
  34. data/test/mail_publisher_test.rb +25 -25
  35. data/test/maven2_builer_test.rb +81 -81
  36. data/test/mock/irc.rb +20 -20
  37. data/test/mock/manager.rb +10 -10
  38. data/test/mock/xmpp4r.rb +19 -19
  39. data/test/rss_publisher_test.rb +21 -21
  40. data/test/test_helper.rb +105 -105
  41. metadata +58 -40
  42. data/lib/cerberus/helper/xchar.rb +0 -61
data/test/config_test.rb CHANGED
@@ -1,46 +1,46 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- require 'cerberus/config'
4
-
5
- class ConfigTest < Test::Unit::TestCase
6
- def test_config
7
- dump_yml(HOME + "/config.yml", {'a'=>'conf', 'd'=>'conf', 'm' => 'conf'})
8
- dump_yml(HOME + "/config/abra.yml", {'a'=>'app', 'd'=>'app', 'g' => 'app'})
9
- cfg = Cerberus::Config.new('abra', :a => 'cli', :b=>'cli', :e=>'cli')
10
-
11
- assert_equal nil, cfg[:mamba]
12
- assert_equal 'cli', cfg[:a]
13
- assert_equal 'cli', cfg[:b]
14
- assert_equal 'app', cfg[:d]
15
- assert_equal 'app', cfg[:g]
16
- assert_equal 'conf', cfg[:m]
17
-
18
-
19
- assert_equal nil, cfg['mamba']
20
- assert_equal 'cli', cfg['a']
21
- assert_equal 'cli', cfg['b']
22
- assert_equal 'app', cfg['d']
23
- assert_equal 'app', cfg['g']
24
- assert_equal 'conf', cfg['m']
25
- end
26
-
27
- def test_deep_merge
28
- cfg = Cerberus::Config.new
29
- cfg.merge!(:hello => {'msg' => {:a202 => 'bye'}})
30
- cfg.merge!(:hello => {:msg => {:a203 => 'hello'}})
31
- cfg.merge!(:hello => {:msg => {:a203 => 'another'}})
32
- cfg.merge!(:hello => {:bread => {:a204 => 'bread'}})
33
-
34
- assert_equal 'bye', cfg[:hello, :msg, :a202]
35
- assert_equal 'another', cfg[:hello, :msg, :a203]
36
- assert_equal 'bread', cfg[:hello, :bread, :a204]
37
- end
38
-
39
- def test_deep_merge_not_overwrite
40
- cfg = Cerberus::Config.new
41
- cfg.merge!({:hello => {'msg' => {:a202 => 'bye'}}}, false)
42
- cfg.merge!({:hello => {:msg => {:a202 => 'hello'}}}, false)
43
-
44
- assert_equal 'bye', cfg[:hello, :msg, :a202]
45
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ require 'cerberus/config'
4
+
5
+ class ConfigTest < Test::Unit::TestCase
6
+ def test_config
7
+ dump_yml(HOME + "/config.yml", {'a'=>'conf', 'd'=>'conf', 'm' => 'conf'})
8
+ dump_yml(HOME + "/config/abra.yml", {'a'=>'app', 'd'=>'app', 'g' => 'app'})
9
+ cfg = Cerberus::Config.new('abra', :a => 'cli', :b=>'cli', :e=>'cli')
10
+
11
+ assert_equal nil, cfg[:mamba]
12
+ assert_equal 'cli', cfg[:a]
13
+ assert_equal 'cli', cfg[:b]
14
+ assert_equal 'app', cfg[:d]
15
+ assert_equal 'app', cfg[:g]
16
+ assert_equal 'conf', cfg[:m]
17
+
18
+
19
+ assert_equal nil, cfg['mamba']
20
+ assert_equal 'cli', cfg['a']
21
+ assert_equal 'cli', cfg['b']
22
+ assert_equal 'app', cfg['d']
23
+ assert_equal 'app', cfg['g']
24
+ assert_equal 'conf', cfg['m']
25
+ end
26
+
27
+ def test_deep_merge
28
+ cfg = Cerberus::Config.new
29
+ cfg.merge!(:hello => {'msg' => {:a202 => 'bye'}})
30
+ cfg.merge!(:hello => {:msg => {:a203 => 'hello'}})
31
+ cfg.merge!(:hello => {:msg => {:a203 => 'another'}})
32
+ cfg.merge!(:hello => {:bread => {:a204 => 'bread'}})
33
+
34
+ assert_equal 'bye', cfg[:hello, :msg, :a202]
35
+ assert_equal 'another', cfg[:hello, :msg, :a203]
36
+ assert_equal 'bread', cfg[:hello, :bread, :a204]
37
+ end
38
+
39
+ def test_deep_merge_not_overwrite
40
+ cfg = Cerberus::Config.new
41
+ cfg.merge!({:hello => {'msg' => {:a202 => 'bye'}}}, false)
42
+ cfg.merge!({:hello => {:msg => {:a202 => 'hello'}}}, false)
43
+
44
+ assert_equal 'bye', cfg[:hello, :msg, :a202]
45
+ end
46
46
  end
@@ -1,287 +1,288 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
- require 'mock/marshmallow'
3
- require 'cerberus/cli'
4
-
5
- require 'action_mailer'
6
-
7
- class FunctionalTest < Test::Unit::TestCase
8
- def setup
9
- FileUtils.rm_rf HOME
10
- ActionMailer::Base.deliveries.clear
11
- end
12
-
13
- def teardown
14
- Dir.chdir HOME + '/../' #We need change working directory to some non-removable dir otherwise we would have warning after removing that working directory absent
15
- FileUtils.rm_rf HOME
16
- end
17
-
18
- def test_add_by_url
19
- assert !File.exists?(HOME + '/config/svn_repo.yml')
20
-
21
- command = Cerberus::AddCommand.new(" #{SVN_URL} ", :quiet => true)
22
- command.run
23
-
24
- assert File.exists?(HOME + '/config/svn_repo.yml')
25
- scm_conf = load_yml(HOME + '/config/svn_repo.yml')['scm']
26
- assert_equal 'svn', scm_conf['type']
27
- assert_equal SVN_URL, scm_conf['url']
28
-
29
- assert File.exists?(HOME + '/config.yml')
30
- end
31
-
32
- def test_add_by_dir
33
- sources_dir = File.dirname(__FILE__) + '/..'
34
-
35
- command = Cerberus::AddCommand.new(sources_dir, :quiet => true)
36
- command.run
37
-
38
- project_config = HOME + "/config/#{File.basename(File.expand_path(sources_dir))}.yml" #name of added application should be calculated from File System path
39
-
40
- assert File.exists?(project_config)
41
- scm_conf = load_yml(project_config)['scm']
42
- assert_equal 'svn', scm_conf['type']
43
- assert_match %r{svn(\+ssh)?://(\w+@)?rubyforge.org/var/svn/cerberus}, scm_conf['url']
44
-
45
- assert File.exists?(HOME + '/config.yml')
46
- end
47
-
48
- def test_build
49
- add_application('myapp', SVN_URL)
50
-
51
- build = Cerberus::BuildCommand.new('myapp', :changeset_url => 'http://someurl.changeset.com/')
52
- build.run
53
- assert_equal 1, ActionMailer::Base.deliveries.size #first email that project was setup
54
- mail = ActionMailer::Base.deliveries[0]
55
- output = mail.body
56
-
57
- #Check outpus that run needed tasks
58
- assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, output
59
- assert output !~ /Task 'custom1' has been invoked/
60
- assert_equal '[myapp] Cerberus set up for project (#2)', mail.subject
61
- assert output =~ %r{http://someurl.changeset.com/2}
62
-
63
- status_file = HOME + '/work/myapp/status.log'
64
- assert File.exists?(status_file)
65
- assert build_successful?(status_file)
66
- assert 1, Dir[HOME + "/work/rake_cust/logs/*-setup.log"].size
67
-
68
- FileUtils.rm status_file
69
- build = Cerberus::BuildCommand.new('myapp')
70
- build.run
71
- assert File.exists?(status_file)
72
- assert build_successful?(status_file)
73
- assert_equal :setup, build.status.current_state
74
- assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup
75
- assert 2, Dir[HOME + "/work/rake_cust/logs/*.log"].size
76
-
77
- build = Cerberus::BuildCommand.new('myapp', :force => true)
78
- build.run
79
- assert_equal :successful, build.status.current_state
80
- assert_equal 2, ActionMailer::Base.deliveries.size #Number of mails not changed
81
- assert 2, Dir[HOME + "/work/rake_cust/logs/*.log"].size #even if sources unchanged
82
-
83
- #remove status file to run project again
84
- FileUtils.rm status_file
85
- add_test_case_to_project('myapp', 'assert false') #if assertion failed
86
- build = Cerberus::BuildCommand.new('myapp')
87
- build.run
88
- assert !build_successful?(status_file)
89
- assert_equal :broken, build.status.current_state
90
- assert_equal 3, ActionMailer::Base.deliveries.size #We should receive mail if project fails
91
-
92
-
93
- add_test_case_to_project('myapp', 'raise "Some exception here"') #if we have exception
94
- build = Cerberus::BuildCommand.new('myapp', :force => true)
95
- build.run
96
- assert !build_successful?(status_file)
97
- assert_equal :broken, build.status.current_state
98
-
99
- subject = ActionMailer::Base.deliveries.last.subject
100
- assert_match /and getting worse/, subject
101
-
102
- #remove status file to run project again
103
- FileUtils.rm status_file
104
- build = Cerberus::BuildCommand.new('myapp')
105
- build.run
106
- assert !build_successful?(status_file)
107
- assert_equal :broken, build.status.current_state
108
- end
109
-
110
- def test_have_no_awkward_header
111
- add_application('myapp', SVN_URL, 'publisher' => {'active' => 'mail'})
112
-
113
- build = Cerberus::BuildCommand.new('myapp')
114
- build.run
115
-
116
- assert build.scm.last_commit_message !~ /-rHEAD -v/
117
- assert_equal 0, build.scm.last_commit_message.index('-' * 72)
118
- end
119
-
120
- def test_send_on_different_events
121
- add_application('myapp', SVN_URL, 'publisher' => {'mail' => {'on_event' => 'none'}, 'on_event' => 'all'})
122
- build = Cerberus::BuildCommand.new('myapp')
123
- build.run
124
- assert_equal 0, ActionMailer::Base.deliveries.size
125
-
126
-
127
- add_application('myapp', SVN_URL, 'publisher' => {'mail' => {'on_event' => 'all'}, 'on_event' => 'none'})
128
- build = Cerberus::BuildCommand.new('myapp')
129
- build.run
130
- assert_equal 1, ActionMailer::Base.deliveries.size
131
- end
132
-
133
- def test_multiply_publishers_without_configuration
134
- add_application('myapp', SVN_URL, 'publisher' => {'active' => 'mail , jabber , irc, dddd'})
135
-
136
- build = Cerberus::BuildCommand.new('myapp')
137
-
138
- begin
139
- build.run
140
- rescue RuntimeError => e
141
- assert_equal 'Publisher have no configuration: jabber', e.message
142
- else
143
- assert false
144
- end
145
- end
146
-
147
- def test_application_and_config_together
148
- add_config('publisher' => {'active' => 'jabber'})
149
- add_application('myapp', SVN_URL)
150
- build = Cerberus::BuildCommand.new('myapp')
151
-
152
- begin
153
- build.run
154
- rescue RuntimeError => e
155
- assert_equal 'Publisher have no configuration: jabber', e.message
156
- else
157
- assert false
158
- end
159
- end
160
-
161
- def test_batch_running
162
- add_application('myapp1', SVN_URL)
163
- add_application('myapp2', SVN_URL)
164
- add_application('myapp3', SVN_URL)
165
- add_application('myapp4', SVN_URL)
166
-
167
- build = Cerberus::BuildAllCommand.new
168
- build.run
169
-
170
- for i in 1..4 do
171
- status_file = HOME + "/work/myapp#{i}/status.log"
172
- assert File.exists?(status_file)
173
- assert build_successful?(status_file)
174
- end
175
- end
176
-
177
- def test_custom_task_for_rake
178
- add_application('rake_cust', SVN_URL, 'builder' => {'rake' => {'task' => 'custom1 custom2'}})
179
- build = Cerberus::BuildAllCommand.new
180
- build.run
181
- assert_equal 1, ActionMailer::Base.deliveries.size
182
- output = ActionMailer::Base.deliveries[0].body
183
- assert_match /Task 'custom1' has been invoked/, output
184
- assert_match /Task 'custom2' has been invoked/, output
185
- end
186
-
187
- def test_logs_disabled
188
- add_application('rake_cust', SVN_URL, 'log' => {'enable' => false})
189
- build = Cerberus::BuildAllCommand.new
190
- build.run
191
-
192
- assert !File.exists?(HOME + "/work/rake_cust/logs")
193
- end
194
-
195
- def test_darcs
196
- add_application('darcsapp', DARCS_URL, :scm => {:type => 'darcs'})
197
-
198
- build = Cerberus::BuildCommand.new('darcsapp')
199
- build.run
200
- assert build.scm.has_changes?
201
- assert_equal 1, ActionMailer::Base.deliveries.size #first email that project was setup
202
- mail = ActionMailer::Base.deliveries[0]
203
- output = mail.body
204
-
205
- #Check outpus that run needed tasks
206
- assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, output
207
- assert output !~ /Task 'custom1' has been invoked/
208
- assert_equal '[darcsapp] Cerberus set up for project (#20061010090920)', mail.subject
209
-
210
- status_file = HOME + '/work/darcsapp/status.log'
211
- assert File.exists?(status_file)
212
- assert build_successful?(status_file)
213
- assert 1, Dir[HOME + "/work/darcsapp/logs/*.log"].size
214
-
215
- #There were no changes - no reaction should be
216
- build = Cerberus::BuildCommand.new('darcsapp')
217
- build.run
218
- assert_equal false, build.scm.has_changes?
219
- assert_equal 1, ActionMailer::Base.deliveries.size #first email that project was setup
220
- assert 1, Dir[HOME + "/work/darcsapp/logs/*.log"].size
221
-
222
- #now we add new broken test
223
- test_case_name = "test/#{rand(10000)}_test.rb"
224
- File.open(DARCS_REPO + '/' + test_case_name, 'w') { |f|
225
- f << "require 'test/unit'
226
- class A#{rand(10000)}Test < Test::Unit::TestCase
227
- def test_ok
228
- assert false
229
- end
230
- end"
231
- }
232
-
233
- curr_dir = Dir.pwd
234
- Dir.chdir DARCS_REPO
235
- `darcs add #{test_case_name}`
236
- `darcs record -a -A test@gmail.com -m somepatch`
237
- Dir.chdir curr_dir
238
-
239
- build = Cerberus::BuildCommand.new('darcsapp')
240
- build.run
241
- assert build.scm.has_changes?
242
- assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup
243
- assert 2, Dir[HOME + "/work/darcsapp/logs/*.log"].size
244
-
245
- build = Cerberus::BuildCommand.new('darcsapp')
246
- build.run
247
- assert_equal false, build.scm.has_changes?
248
- assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup
249
- assert 2, Dir[HOME + "/work/darcsapp/logs/*.log"].size
250
-
251
- #Now we broke remote repository (imiitate that network unaccessage)
252
- FileUtils.rm_rf DARCS_REPO
253
- build = Cerberus::BuildCommand.new('darcsapp')
254
- build.run
255
- assert_equal false, build.scm.has_changes?
256
- end
257
-
258
- def test_campfire_publisher
259
- #there were no any messages cause login/password is incorrect. We just check that there was no any exceptions
260
- add_application('campapp', SVN_URL, 'publisher' => {'active' => 'campfire', 'campfire' =>
261
- {'url' => 'http://mail@gmail.com:somepwd@cerberustool.campfirenow.com/room/5166022'}
262
- })
263
-
264
- build = Cerberus::BuildCommand.new('campapp')
265
- build.run
266
-
267
- assert_equal 2, Marshmallow.counter
268
- end
269
-
270
- def test_correct_migration_from_previous_status
271
- status_fn = TEMP_DIR + '/test_status_file.log'
272
-
273
- status = Cerberus::Status.new(status_fn)
274
- assert_equal nil, status.previous_build_successful
275
- assert_equal nil, status.current_build_successful
276
-
277
- IO.write(status_fn, 'failed')
278
- status = Cerberus::Status.new(status_fn)
279
- assert_equal nil, status.current_build_successful
280
- assert_equal false, status.previous_build_successful
281
-
282
- status.keep(true, 1232, 0)
283
- assert_equal true, status.current_build_successful
284
- assert_equal false, status.previous_build_successful
285
- assert_equal :revival, status.current_state
286
- end
287
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'mock/marshmallow'
3
+ require 'cerberus/cli'
4
+
5
+ require 'action_mailer'
6
+
7
+ class FunctionalTest < Test::Unit::TestCase
8
+ def setup
9
+ FileUtils.rm_rf HOME
10
+ ActionMailer::Base.deliveries.clear
11
+ end
12
+
13
+ def teardown
14
+ dir = HOME + '/../'
15
+ Dir.chdir(dir) if test(?d, dir) #We need change working directory to some non-removable dir otherwise we would have warning after removing that working directory absent
16
+ FileUtils.rm_rf HOME
17
+ end
18
+
19
+ def test_add_by_url
20
+ assert !File.exists?(HOME + '/config/svn_repo.yml')
21
+
22
+ command = Cerberus::AddCommand.new(" #{SVN_URL} ", :quiet => true)
23
+ command.run
24
+
25
+ assert File.exists?(HOME + '/config/svn_repo.yml')
26
+ scm_conf = load_yml(HOME + '/config/svn_repo.yml')['scm']
27
+ assert_equal 'svn', scm_conf['type']
28
+ assert_equal SVN_URL, scm_conf['url']
29
+
30
+ assert File.exists?(HOME + '/config.yml')
31
+ end
32
+
33
+ def test_add_by_dir
34
+ sources_dir = File.dirname(__FILE__) + '/..'
35
+
36
+ command = Cerberus::AddCommand.new(sources_dir, :quiet => true)
37
+ command.run
38
+
39
+ project_config = HOME + "/config/#{File.basename(File.expand_path(sources_dir))}.yml" #name of added application should be calculated from File System path
40
+
41
+ assert File.exists?(project_config)
42
+ scm_conf = load_yml(project_config)['scm']
43
+ assert_equal 'svn', scm_conf['type']
44
+ assert_match %r{svn(\+ssh)?://(\w+@)?rubyforge.org/var/svn/cerberus}, scm_conf['url']
45
+
46
+ assert File.exists?(HOME + '/config.yml')
47
+ end
48
+
49
+ def test_build
50
+ add_application('myapp', SVN_URL)
51
+
52
+ build = Cerberus::BuildCommand.new('myapp', :changeset_url => 'http://someurl.changeset.com/')
53
+ build.run
54
+ assert_equal 1, ActionMailer::Base.deliveries.size #first email that project was setup
55
+ mail = ActionMailer::Base.deliveries[0]
56
+ output = mail.body
57
+
58
+ #Check outpus that run needed tasks
59
+ assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, output
60
+ assert output !~ /Task 'custom1' has been invoked/
61
+ assert_equal '[myapp] Cerberus set up for project (#2)', mail.subject
62
+ assert output =~ %r{http://someurl.changeset.com/2}
63
+
64
+ status_file = HOME + '/work/myapp/status.log'
65
+ assert File.exists?(status_file)
66
+ assert build_successful?(status_file)
67
+ assert 1, Dir[HOME + "/work/rake_cust/logs/*-setup.log"].size
68
+
69
+ FileUtils.rm status_file
70
+ build = Cerberus::BuildCommand.new('myapp')
71
+ build.run
72
+ assert File.exists?(status_file)
73
+ assert build_successful?(status_file)
74
+ assert_equal :setup, build.status.current_state
75
+ assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup
76
+ assert 2, Dir[HOME + "/work/rake_cust/logs/*.log"].size
77
+
78
+ build = Cerberus::BuildCommand.new('myapp', :force => true)
79
+ build.run
80
+ assert_equal :successful, build.status.current_state
81
+ assert_equal 2, ActionMailer::Base.deliveries.size #Number of mails not changed
82
+ assert 2, Dir[HOME + "/work/rake_cust/logs/*.log"].size #even if sources unchanged
83
+
84
+ #remove status file to run project again
85
+ FileUtils.rm status_file
86
+ add_test_case_to_project('myapp', 'assert false') #if assertion failed
87
+ build = Cerberus::BuildCommand.new('myapp')
88
+ build.run
89
+ assert !build_successful?(status_file)
90
+ assert_equal :broken, build.status.current_state
91
+ assert_equal 3, ActionMailer::Base.deliveries.size #We should receive mail if project fails
92
+
93
+
94
+ add_test_case_to_project('myapp', 'raise "Some exception here"') #if we have exception
95
+ build = Cerberus::BuildCommand.new('myapp', :force => true)
96
+ build.run
97
+ assert !build_successful?(status_file)
98
+ assert_equal :broken, build.status.current_state
99
+
100
+ subject = ActionMailer::Base.deliveries.last.subject
101
+ assert_match /and getting worse/, subject
102
+
103
+ #remove status file to run project again
104
+ FileUtils.rm status_file
105
+ build = Cerberus::BuildCommand.new('myapp')
106
+ build.run
107
+ assert !build_successful?(status_file)
108
+ assert_equal :broken, build.status.current_state
109
+ end
110
+
111
+ def test_have_no_awkward_header
112
+ add_application('myapp', SVN_URL, 'publisher' => {'active' => 'mail'})
113
+
114
+ build = Cerberus::BuildCommand.new('myapp')
115
+ build.run
116
+
117
+ assert build.scm.last_commit_message !~ /-rHEAD -v/
118
+ assert_equal 0, build.scm.last_commit_message.index('-' * 72)
119
+ end
120
+
121
+ def test_send_on_different_events
122
+ add_application('myapp', SVN_URL, 'publisher' => {'mail' => {'on_event' => 'none'}, 'on_event' => 'all'})
123
+ build = Cerberus::BuildCommand.new('myapp')
124
+ build.run
125
+ assert_equal 0, ActionMailer::Base.deliveries.size
126
+
127
+
128
+ add_application('myapp', SVN_URL, 'publisher' => {'mail' => {'on_event' => 'all'}, 'on_event' => 'none'})
129
+ build = Cerberus::BuildCommand.new('myapp')
130
+ build.run
131
+ assert_equal 1, ActionMailer::Base.deliveries.size
132
+ end
133
+
134
+ def test_multiply_publishers_without_configuration
135
+ add_application('myapp', SVN_URL, 'publisher' => {'active' => 'mail , jabber , irc, dddd'})
136
+
137
+ build = Cerberus::BuildCommand.new('myapp')
138
+
139
+ begin
140
+ build.run
141
+ rescue RuntimeError => e
142
+ assert_equal 'Publisher have no configuration: jabber', e.message
143
+ else
144
+ assert false
145
+ end
146
+ end
147
+
148
+ def test_application_and_config_together
149
+ add_config('publisher' => {'active' => 'jabber'})
150
+ add_application('myapp', SVN_URL)
151
+ build = Cerberus::BuildCommand.new('myapp')
152
+
153
+ begin
154
+ build.run
155
+ rescue RuntimeError => e
156
+ assert_equal 'Publisher have no configuration: jabber', e.message
157
+ else
158
+ assert false
159
+ end
160
+ end
161
+
162
+ def test_batch_running
163
+ add_application('myapp1', SVN_URL)
164
+ add_application('myapp2', SVN_URL)
165
+ add_application('myapp3', SVN_URL)
166
+ add_application('myapp4', SVN_URL)
167
+
168
+ build = Cerberus::BuildAllCommand.new
169
+ build.run
170
+
171
+ for i in 1..4 do
172
+ status_file = HOME + "/work/myapp#{i}/status.log"
173
+ assert File.exists?(status_file)
174
+ assert build_successful?(status_file)
175
+ end
176
+ end
177
+
178
+ def test_custom_task_for_rake
179
+ add_application('rake_cust', SVN_URL, 'builder' => {'rake' => {'task' => 'custom1 custom2'}})
180
+ build = Cerberus::BuildAllCommand.new
181
+ build.run
182
+ assert_equal 1, ActionMailer::Base.deliveries.size
183
+ output = ActionMailer::Base.deliveries[0].body
184
+ assert_match /Task 'custom1' has been invoked/, output
185
+ assert_match /Task 'custom2' has been invoked/, output
186
+ end
187
+
188
+ def test_logs_disabled
189
+ add_application('rake_cust', SVN_URL, 'log' => {'enable' => false})
190
+ build = Cerberus::BuildAllCommand.new
191
+ build.run
192
+
193
+ assert !File.exists?(HOME + "/work/rake_cust/logs")
194
+ end
195
+
196
+ def test_darcs
197
+ add_application('darcsapp', DARCS_URL, :scm => {:type => 'darcs'})
198
+
199
+ build = Cerberus::BuildCommand.new('darcsapp')
200
+ build.run
201
+ assert build.scm.has_changes?
202
+ assert_equal 1, ActionMailer::Base.deliveries.size #first email that project was setup
203
+ mail = ActionMailer::Base.deliveries[0]
204
+ output = mail.body
205
+
206
+ #Check outpus that run needed tasks
207
+ assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, output
208
+ assert output !~ /Task 'custom1' has been invoked/
209
+ assert_equal '[darcsapp] Cerberus set up for project (#20061010090920)', mail.subject
210
+
211
+ status_file = HOME + '/work/darcsapp/status.log'
212
+ assert File.exists?(status_file)
213
+ assert build_successful?(status_file)
214
+ assert 1, Dir[HOME + "/work/darcsapp/logs/*.log"].size
215
+
216
+ #There were no changes - no reaction should be
217
+ build = Cerberus::BuildCommand.new('darcsapp')
218
+ build.run
219
+ assert_equal false, build.scm.has_changes?
220
+ assert_equal 1, ActionMailer::Base.deliveries.size #first email that project was setup
221
+ assert 1, Dir[HOME + "/work/darcsapp/logs/*.log"].size
222
+
223
+ #now we add new broken test
224
+ test_case_name = "test/#{rand(10000)}_test.rb"
225
+ File.open(DARCS_REPO + '/' + test_case_name, 'w') { |f|
226
+ f << "require 'test/unit'
227
+ class A#{rand(10000)}Test < Test::Unit::TestCase
228
+ def test_ok
229
+ assert false
230
+ end
231
+ end"
232
+ }
233
+
234
+ curr_dir = Dir.pwd
235
+ Dir.chdir DARCS_REPO
236
+ `darcs add #{test_case_name}`
237
+ `darcs record -a -A test@gmail.com -m somepatch`
238
+ Dir.chdir curr_dir
239
+
240
+ build = Cerberus::BuildCommand.new('darcsapp')
241
+ build.run
242
+ assert build.scm.has_changes?
243
+ assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup
244
+ assert 2, Dir[HOME + "/work/darcsapp/logs/*.log"].size
245
+
246
+ build = Cerberus::BuildCommand.new('darcsapp')
247
+ build.run
248
+ assert_equal false, build.scm.has_changes?
249
+ assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup
250
+ assert 2, Dir[HOME + "/work/darcsapp/logs/*.log"].size
251
+
252
+ #Now we broke remote repository (imiitate that network unaccessage)
253
+ FileUtils.rm_rf DARCS_REPO
254
+ build = Cerberus::BuildCommand.new('darcsapp')
255
+ build.run
256
+ assert_equal false, build.scm.has_changes?
257
+ end
258
+
259
+ def test_campfire_publisher
260
+ #there were no any messages cause login/password is incorrect. We just check that there was no any exceptions
261
+ add_application('campapp', SVN_URL, 'publisher' => {'active' => 'campfire', 'campfire' =>
262
+ {'url' => 'http://mail@gmail.com:somepwd@cerberustool.campfirenow.com/room/5166022'}
263
+ })
264
+
265
+ build = Cerberus::BuildCommand.new('campapp')
266
+ build.run
267
+
268
+ assert_equal 2, Marshmallow.counter
269
+ end
270
+
271
+ def test_correct_migration_from_previous_status
272
+ status_fn = TEMP_DIR + '/test_status_file.log'
273
+
274
+ status = Cerberus::Status.new(status_fn)
275
+ assert_equal nil, status.previous_build_successful
276
+ assert_equal nil, status.current_build_successful
277
+
278
+ IO.write(status_fn, 'failed')
279
+ status = Cerberus::Status.new(status_fn)
280
+ assert_equal nil, status.current_build_successful
281
+ assert_equal false, status.previous_build_successful
282
+
283
+ status.keep(true, 1232, 0)
284
+ assert_equal true, status.current_build_successful
285
+ assert_equal false, status.previous_build_successful
286
+ assert_equal :revival, status.current_state
287
+ end
288
+ end