sunshine 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/History.txt +237 -0
  2. data/Manifest.txt +70 -0
  3. data/README.txt +277 -0
  4. data/Rakefile +46 -0
  5. data/bin/sunshine +5 -0
  6. data/examples/deploy.rb +61 -0
  7. data/examples/deploy_tasks.rake +112 -0
  8. data/examples/standalone_deploy.rb +31 -0
  9. data/lib/commands/add.rb +96 -0
  10. data/lib/commands/default.rb +169 -0
  11. data/lib/commands/list.rb +322 -0
  12. data/lib/commands/restart.rb +62 -0
  13. data/lib/commands/rm.rb +83 -0
  14. data/lib/commands/run.rb +151 -0
  15. data/lib/commands/start.rb +72 -0
  16. data/lib/commands/stop.rb +61 -0
  17. data/lib/sunshine/app.rb +876 -0
  18. data/lib/sunshine/binder.rb +70 -0
  19. data/lib/sunshine/crontab.rb +143 -0
  20. data/lib/sunshine/daemon.rb +380 -0
  21. data/lib/sunshine/daemons/ar_sendmail.rb +28 -0
  22. data/lib/sunshine/daemons/delayed_job.rb +30 -0
  23. data/lib/sunshine/daemons/nginx.rb +104 -0
  24. data/lib/sunshine/daemons/rainbows.rb +35 -0
  25. data/lib/sunshine/daemons/server.rb +66 -0
  26. data/lib/sunshine/daemons/unicorn.rb +26 -0
  27. data/lib/sunshine/dependencies.rb +103 -0
  28. data/lib/sunshine/dependency_lib.rb +200 -0
  29. data/lib/sunshine/exceptions.rb +54 -0
  30. data/lib/sunshine/healthcheck.rb +83 -0
  31. data/lib/sunshine/output.rb +131 -0
  32. data/lib/sunshine/package_managers/apt.rb +48 -0
  33. data/lib/sunshine/package_managers/dependency.rb +349 -0
  34. data/lib/sunshine/package_managers/gem.rb +54 -0
  35. data/lib/sunshine/package_managers/yum.rb +62 -0
  36. data/lib/sunshine/remote_shell.rb +241 -0
  37. data/lib/sunshine/repo.rb +128 -0
  38. data/lib/sunshine/repos/git_repo.rb +122 -0
  39. data/lib/sunshine/repos/rsync_repo.rb +29 -0
  40. data/lib/sunshine/repos/svn_repo.rb +78 -0
  41. data/lib/sunshine/server_app.rb +554 -0
  42. data/lib/sunshine/shell.rb +384 -0
  43. data/lib/sunshine.rb +391 -0
  44. data/templates/logrotate/logrotate.conf.erb +11 -0
  45. data/templates/nginx/nginx.conf.erb +109 -0
  46. data/templates/nginx/nginx_optimize.conf +23 -0
  47. data/templates/nginx/nginx_proxy.conf +13 -0
  48. data/templates/rainbows/rainbows.conf.erb +18 -0
  49. data/templates/tasks/sunshine.rake +114 -0
  50. data/templates/unicorn/unicorn.conf.erb +6 -0
  51. data/test/fixtures/app_configs/test_app.yml +11 -0
  52. data/test/fixtures/sunshine_test/test_upload +0 -0
  53. data/test/mocks/mock_object.rb +179 -0
  54. data/test/mocks/mock_open4.rb +117 -0
  55. data/test/test_helper.rb +188 -0
  56. data/test/unit/test_app.rb +489 -0
  57. data/test/unit/test_binder.rb +20 -0
  58. data/test/unit/test_crontab.rb +128 -0
  59. data/test/unit/test_git_repo.rb +26 -0
  60. data/test/unit/test_healthcheck.rb +70 -0
  61. data/test/unit/test_nginx.rb +107 -0
  62. data/test/unit/test_rainbows.rb +26 -0
  63. data/test/unit/test_remote_shell.rb +102 -0
  64. data/test/unit/test_repo.rb +42 -0
  65. data/test/unit/test_server.rb +324 -0
  66. data/test/unit/test_server_app.rb +425 -0
  67. data/test/unit/test_shell.rb +97 -0
  68. data/test/unit/test_sunshine.rb +157 -0
  69. data/test/unit/test_svn_repo.rb +55 -0
  70. data/test/unit/test_unicorn.rb +22 -0
  71. metadata +217 -0
@@ -0,0 +1,70 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestHealthcheck < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @remote_shell = mock_remote_shell
7
+ @health = Sunshine::Healthcheck.new "somepath", @remote_shell
8
+
9
+ @test_disabled = "test -f #{@health.disabled_file}"
10
+ @test_enabled = "test -f #{@health.enabled_file}"
11
+ end
12
+
13
+
14
+ def test_initialize
15
+ assert_equal @remote_shell, @health.shell
16
+ assert_equal "somepath/health.enabled", @health.enabled_file
17
+ assert_equal "somepath/health.disabled", @health.disabled_file
18
+ end
19
+
20
+
21
+ def test_disable
22
+ @health.disable
23
+
24
+ cmd = "touch #{@health.disabled_file} && rm -f #{@health.enabled_file}"
25
+ assert_ssh_call cmd
26
+ end
27
+
28
+
29
+ def test_enable
30
+ @health.enable
31
+
32
+ cmd = "rm -f #{@health.disabled_file} && touch #{@health.enabled_file}"
33
+ assert_ssh_call cmd
34
+ end
35
+
36
+
37
+ def test_remove
38
+ @health.remove
39
+
40
+ cmd = "rm -f #{@health.disabled_file} #{@health.enabled_file}"
41
+ assert_ssh_call cmd
42
+ end
43
+
44
+
45
+ def test_status_down
46
+ @remote_shell.set_mock_response 1,
47
+ @test_disabled => [:err, ""],
48
+ @test_enabled => [:err, ""]
49
+
50
+ assert_equal(:down, @health.status)
51
+
52
+ assert_ssh_call @test_disabled
53
+ assert_ssh_call @test_enabled
54
+ end
55
+
56
+
57
+ def test_status_ok
58
+ @remote_shell.set_mock_response 1, @test_disabled => [:err, ""]
59
+ @remote_shell.set_mock_response 0, @test_enabled => [:out, ""]
60
+
61
+ assert_equal(:enabled, @health.status)
62
+ end
63
+
64
+
65
+ def test_status_disabled
66
+ @remote_shell.set_mock_response 0, @test_disabled => [:out, ""]
67
+
68
+ assert_equal(:disabled, @health.status)
69
+ end
70
+ end
@@ -0,0 +1,107 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestNginx < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @app = Sunshine::App.new TEST_APP_CONFIG_FILE
7
+ @app.server_apps.first.extend MockOpen4
8
+ @app.server_apps.first.shell.extend MockOpen4
9
+ use_remote_shell @app.server_apps.first.shell
10
+
11
+ @passenger = Sunshine::Nginx.new @app
12
+ @nginx = Sunshine::Nginx.new @app, :port => 5000, :point_to => @passenger
13
+ @gemout = <<-STR
14
+
15
+ *** LOCAL GEMS ***
16
+
17
+ passenger (2.2.4)
18
+ Author: Phusion - http://www.phusion.nl/
19
+ Rubyforge: http://rubyforge.org/projects/passenger
20
+ Homepage: http://www.modrails.com/
21
+ Installed at: /Library/Ruby/Gems/1.8
22
+
23
+ Apache module for Ruby on Rails support.
24
+ STR
25
+ end
26
+
27
+
28
+ def test_cmd
29
+ ds = @nginx.app.server_apps.first.shell
30
+ ds.set_mock_response 0, "gem list passenger -d" => [:out, @gemout]
31
+
32
+ @nginx.start
33
+ @nginx.stop
34
+
35
+ assert_ssh_call start_cmd(@passenger)
36
+ assert_ssh_call stop_cmd(@passenger)
37
+ end
38
+
39
+
40
+ def test_custom_sudo_cmd
41
+ ds = @nginx.app.server_apps.first.shell
42
+ ds.set_mock_response 0, "gem list passenger -d" => [:out, @gemout]
43
+
44
+ @nginx.sudo = "someuser"
45
+
46
+ @nginx.start
47
+ @nginx.stop
48
+
49
+ assert_ssh_call start_cmd(@passenger), ds, :sudo => @nginx.sudo
50
+ assert_ssh_call stop_cmd(@passenger), ds, :sudo => @nginx.sudo
51
+ end
52
+
53
+
54
+ def test_sudo_cmd
55
+ ds = @passenger.app.server_apps.first.shell
56
+ ds.set_mock_response 0, "gem list passenger -d" => [:out, @gemout]
57
+
58
+ @passenger.start
59
+ @passenger.stop
60
+
61
+ assert_equal true, @passenger.sudo
62
+ assert_ssh_call start_cmd(@passenger), ds, :sudo => true
63
+ assert_ssh_call stop_cmd(@passenger), ds, :sudo => true
64
+ end
65
+
66
+
67
+ def test_setup_passenger
68
+ ds = @passenger.app.server_apps.first.shell
69
+ ds.set_mock_response 0, "gem list passenger -d" => [:out, @gemout]
70
+
71
+ @passenger.setup do |ds, binder|
72
+ assert binder.sudo
73
+ assert binder.use_passenger?
74
+ assert_equal "/Library/Ruby/Gems/1.8/gems/passenger-2.2.4",
75
+ binder.passenger_root
76
+ end
77
+ end
78
+
79
+
80
+ def test_setup
81
+ ds = @nginx.app.server_apps.first.shell
82
+ ds.set_mock_response 0, "gem list passenger -d" => [:out, @gemout]
83
+
84
+ @nginx.setup do |ds, binder|
85
+ assert !binder.sudo
86
+ assert !binder.use_passenger?
87
+ assert_equal "/Library/Ruby/Gems/1.8/gems/passenger-2.2.4",
88
+ binder.passenger_root
89
+ end
90
+ end
91
+
92
+
93
+ ## Helper methods
94
+
95
+ def start_cmd svr, sudo=false
96
+ sudo = sudo ? "sudo " : ""
97
+ "#{sudo}#{svr.bin} -c #{svr.config_file_path}"
98
+ end
99
+
100
+
101
+ def stop_cmd svr, sudo=false
102
+ sudo = sudo ? "sudo " : ""
103
+ cmd = "#{sudo }test -f #{svr.pid} && kill -QUIT $(cat #{svr.pid})"+
104
+ " || echo 'No #{svr.name} process to stop for #{svr.app.name}';"
105
+ cmd << "sleep 2 ; rm -f #{svr.pid};"
106
+ end
107
+ end
@@ -0,0 +1,26 @@
1
+ require 'test/test_helper'
2
+ require 'test/unit/test_unicorn'
3
+
4
+ class TestRainbows < TestUnicorn
5
+
6
+ def setup
7
+ super
8
+ @app.each{|sa| sa.shell.extend MockOpen4}
9
+ @server = Sunshine::Rainbows.new @app
10
+ end
11
+
12
+
13
+ def test_setup
14
+ @server.use_concurrency :model => :TreadSpawn, :timeout => 1
15
+ @server.setup do |ds, binder|
16
+ assert_equal @server.concurrency, binder.concurrency
17
+ end
18
+ end
19
+
20
+
21
+ def test_use_concurrency
22
+ concurrency = {:model => :ModelName, :timeout => 1, :connections => 500}
23
+ @server.use_concurrency concurrency
24
+ assert_equal concurrency, @server.concurrency
25
+ end
26
+ end
@@ -0,0 +1,102 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestRemoteShell < Test::Unit::TestCase
4
+
5
+ def setup
6
+ mock_remote_shell_popen4
7
+
8
+ @app = Sunshine::App.new TEST_APP_CONFIG_FILE
9
+
10
+ @host = "user@some_server.com"
11
+
12
+ @remote_shell = mock_remote_shell @host
13
+ end
14
+
15
+ def teardown
16
+ @remote_shell.disconnect
17
+ end
18
+
19
+ def test_connect
20
+ assert_ssh_call \
21
+ "echo connected; echo ready; for (( ; ; )); do sleep 10; done"
22
+ assert @remote_shell.connected?
23
+ end
24
+
25
+ def test_disconnect
26
+ @remote_shell.disconnect
27
+ assert !@remote_shell.connected?
28
+ end
29
+
30
+ def test_call
31
+ @remote_shell.call "echo 'line1'; echo 'line2'"
32
+ assert_ssh_call "echo 'line1'; echo 'line2'"
33
+
34
+ @remote_shell.sudo = "sudouser"
35
+ @remote_shell.call "sudocall"
36
+ assert_ssh_call "sudocall", @remote_shell, :sudo => "sudouser"
37
+ end
38
+
39
+ def test_call_with_stderr
40
+ @remote_shell.set_mock_response 1, :err => 'this is an error'
41
+ cmd = "echo 'this is an error'"
42
+ @remote_shell.call cmd
43
+ raise "Didn't raise CmdError on stderr"
44
+ rescue Sunshine::CmdError => e
45
+ ssh_cmd = @remote_shell.send(:ssh_cmd, cmd).join(" ")
46
+ assert_equal "Execution failed with status 1: #{ssh_cmd}", e.message
47
+ end
48
+
49
+ def test_upload
50
+ @remote_shell.upload "test/fixtures/sunshine_test", "sunshine_test"
51
+ assert_rsync "test/fixtures/sunshine_test",
52
+ "#{@remote_shell.host}:sunshine_test"
53
+
54
+ @remote_shell.sudo = "blah"
55
+ @remote_shell.upload "test/fixtures/sunshine_test", "sunshine_test"
56
+ assert_rsync "test/fixtures/sunshine_test",
57
+ "#{@remote_shell.host}:sunshine_test", @remote_shell, "blah"
58
+ end
59
+
60
+ def test_download
61
+ @remote_shell.download "sunshine_test", "."
62
+ assert_rsync "#{@remote_shell.host}:sunshine_test", "."
63
+
64
+ @remote_shell.download "sunshine_test", ".", :sudo => "sudouser"
65
+ assert_rsync "#{@remote_shell.host}:sunshine_test", ".",
66
+ @remote_shell, "sudouser"
67
+ end
68
+
69
+ def test_make_file
70
+ @remote_shell.make_file("some_dir/sunshine_test_file", "test data")
71
+ tmp_file = "#{Sunshine::TMP_DIR}/sunshine_test_file"
72
+ tmp_file = Regexp.escape tmp_file
73
+ assert_rsync(/^#{tmp_file}_[0-9]+/,
74
+ "#{@remote_shell.host}:some_dir/sunshine_test_file")
75
+ end
76
+
77
+ def test_os_name
78
+ @remote_shell.os_name
79
+ assert_ssh_call "uname -s"
80
+ end
81
+
82
+ def test_equality
83
+ ds_equal = Sunshine::RemoteShell.new @host
84
+ ds_diff1 = Sunshine::RemoteShell.new @host, :user => "blarg"
85
+ ds_diff2 = Sunshine::RemoteShell.new "some_other_host"
86
+
87
+ assert_equal ds_equal, @remote_shell
88
+ assert_equal ds_diff1, @remote_shell
89
+ assert ds_diff2 != @remote_shell
90
+ end
91
+
92
+ def test_file?
93
+ @remote_shell.file? "some/file/path"
94
+ assert_ssh_call "test -f some/file/path"
95
+ end
96
+
97
+ def test_symlink
98
+ @remote_shell.symlink "target_file", "sym_name"
99
+ assert_ssh_call "ln -sfT target_file sym_name"
100
+ end
101
+
102
+ end
@@ -0,0 +1,42 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestRepo < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @svn_url = "https://svnurl/to/repo/tag"
7
+ @repo = Sunshine::Repo.new_of_type(:svn, @svn_url)
8
+ @repo.extend MockObject
9
+ end
10
+
11
+ def test_new_of_type
12
+ repo = Sunshine::Repo.new_of_type :svn, @svn_url
13
+ assert_equal Sunshine::SvnRepo, repo.class
14
+ assert_equal @svn_url, repo.url
15
+
16
+ repo = Sunshine::Repo.new_of_type "", @svn_url
17
+ assert_equal Sunshine::Repo, repo.class
18
+ end
19
+
20
+
21
+ def test_get_repo_info
22
+ ds = mock_remote_shell
23
+ begin
24
+ Sunshine::Repo.new(@svn_url).get_repo_info ds, "path/to/repo"
25
+ raise "Didn't raise RepoError when it should have"
26
+ rescue Sunshine::RepoError => e
27
+ msg = "The 'get_info' method must be implemented by child classes"
28
+ assert_equal msg, e.message
29
+ end
30
+ end
31
+
32
+
33
+ def test_checkout_to
34
+ begin
35
+ Sunshine::Repo.new(@svn_url).checkout_to "somepath", mock_remote_shell
36
+ raise "Didn't raise RepoError on checkout_cmd"
37
+ rescue Sunshine::RepoError => e
38
+ msg = "The 'do_checkout' method must be implemented by child classes"
39
+ assert_equal msg, e.message
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,324 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestServer < Test::Unit::TestCase
4
+
5
+ class Server < Sunshine::Server
6
+ def start_cmd
7
+ "test start cmd"
8
+ end
9
+
10
+ def stop_cmd
11
+ "test stop cmd"
12
+ end
13
+ end
14
+
15
+
16
+ def setup
17
+ mock_remote_shell_popen4
18
+ @app = Sunshine::App.new(TEST_APP_CONFIG_FILE).extend MockObject
19
+ @server_app = @app.server_apps.first.extend MockObject
20
+ @app.server_apps.first.shell.extend MockObject
21
+
22
+ @server = Server.new @app
23
+
24
+ @rainbows = Sunshine::Rainbows.new(@app).extend MockObject
25
+ use_remote_shell @server_app.shell
26
+ end
27
+
28
+
29
+ def test_initialize
30
+ assert_server_init
31
+
32
+ config = {
33
+ :point_to => @server,
34
+ :pid => "path/to/pid",
35
+ :bin => "path/to/bin",
36
+ :port => 1234,
37
+ :processes => 10,
38
+ :server_name => "serv1.com",
39
+ :server_apps => ["remote_shell_test"],
40
+ :config_template => "template.erb",
41
+ :config_path => "path/to/config",
42
+ :config_file => "conf_filename.conf",
43
+ :log_path => "path/to/logs",
44
+ :sudo => "sudouser"
45
+ }
46
+
47
+ svr = Server.new @app, config
48
+
49
+ config[:target] = config[:point_to]
50
+ config[:stderr] = "#{config[:log_path]}/server_stderr.log"
51
+ config[:stdout] = "#{config[:log_path]}/server_stdout.log"
52
+
53
+ assert_server_init svr, config
54
+ end
55
+
56
+
57
+ def test_setup
58
+ server = @rainbows
59
+
60
+ server.setup do |sa, binder|
61
+ assert_equal @server_app, sa
62
+
63
+ assert_equal sa.shell, binder.shell
64
+ assert_equal sa.shell.host, binder.server_name
65
+ assert_equal @rainbows.send(:pick_sudo, sa.shell), binder.sudo
66
+ end
67
+
68
+ args = ["rainbows"]
69
+ server.each_server_app do |sa|
70
+ assert sa.method_called?(:install_deps, :args => args)
71
+ end
72
+
73
+ assert server.method_called?(:upload_config_files)
74
+
75
+ assert_ssh_call "mkdir -p #{server.send(:remote_dirs).join(" ")}"
76
+
77
+ assert_rsync(/rainbows\.conf/, "some_server.com:"+
78
+ "/usr/local/my_user/other_app/current/daemons/rainbows/rainbows.conf")
79
+
80
+ assert server.has_setup?
81
+ end
82
+
83
+
84
+ def test_has_setup?
85
+ server = @rainbows
86
+ assert_equal nil, server.instance_variable_get("@setup_successful")
87
+
88
+ @server_app.shell.mock :file?, :args => [server.config_file_path],
89
+ :return => false
90
+
91
+ assert_equal false, server.has_setup?
92
+
93
+ @server_app.shell.mock :file?, :args => [server.config_file_path],
94
+ :return => true
95
+
96
+ assert_equal false, server.has_setup?
97
+ assert_equal true, server.has_setup?(true)
98
+ end
99
+
100
+
101
+ def test_start
102
+ server = @rainbows
103
+ @server_app.shell.mock :file?, :args => [server.config_file_path],
104
+ :return => false
105
+
106
+ server.start do |ds|
107
+ assert_equal @server_app, ds
108
+ end
109
+
110
+ assert server.method_called?(:setup)
111
+
112
+ assert_ssh_call server.start_cmd
113
+ end
114
+
115
+
116
+ def test_start_missing_setup
117
+ server = @rainbows
118
+ @server_app.shell.mock :file?, :args => [server.config_file_path],
119
+ :return => true
120
+
121
+ server.start
122
+
123
+ assert !server.method_called?(:setup)
124
+
125
+ assert_ssh_call server.start_cmd
126
+ end
127
+
128
+
129
+ def test_stop
130
+ server = @rainbows
131
+
132
+ server.stop do |ds|
133
+ assert_equal @server_app, ds
134
+ end
135
+
136
+ assert_ssh_call server.stop_cmd
137
+ end
138
+
139
+
140
+ def test_restart
141
+ server = @rainbows
142
+
143
+ server.restart
144
+
145
+ assert_ssh_call server.restart_cmd
146
+ end
147
+
148
+
149
+ def test_restart_missing_setup
150
+ server = @rainbows
151
+ @server_app.shell.mock :file?, :args => [server.config_file_path],
152
+ :return => true
153
+
154
+ server.restart
155
+
156
+ assert !server.method_called?(:setup)
157
+
158
+ assert_ssh_call server.restart_cmd
159
+ end
160
+
161
+
162
+ def test_restart_with_cmd
163
+ server = @rainbows
164
+ server.instance_variable_set("@restart_cmd", "RESTART!!1!")
165
+
166
+ @server_app.shell.mock :file?, :args => [server.config_file_path],
167
+ :return => false
168
+
169
+ server.restart
170
+
171
+ assert server.method_called?(:setup)
172
+ assert_ssh_call server.restart_cmd
173
+ end
174
+
175
+
176
+ def test_missing_start_stop_cmd
177
+ server = Sunshine::Server.new @app
178
+
179
+ begin
180
+ server.start_cmd
181
+ raise "Should have thrown CriticalDeployError but didn't :("
182
+ rescue Sunshine::CriticalDeployError => e
183
+ assert_equal "@start_cmd undefined. Can't start server", e.message
184
+ end
185
+
186
+ begin
187
+ server.stop_cmd
188
+ raise "Should have thrown CriticalDeployError but didn't :("
189
+ rescue Sunshine::CriticalDeployError => e
190
+ assert_equal "@stop_cmd undefined. Can't stop server", e.message
191
+ end
192
+ end
193
+
194
+
195
+ def test_log_files
196
+ @server.log_files :test_log => "/path/test_log.log",
197
+ :another_test => "/path/another_test.log"
198
+
199
+ assert_equal "/path/test_log.log", @server.log_file(:test_log)
200
+ assert_equal "/path/another_test.log", @server.log_file(:another_test)
201
+ end
202
+
203
+
204
+ def test_upload_config_files
205
+ server = @rainbows
206
+
207
+ server.mock :config_template_files,
208
+ :return => ["rainbows.conf.erb", "test/non_erb.conf"]
209
+
210
+ @app.mock :build_erb, :return => "test_config"
211
+
212
+ server.upload_config_files @server_app.shell
213
+
214
+ args = ["#{server.config_path}/rainbows.conf", "test_config"]
215
+ assert @server_app.shell.method_called?(:make_file, :args => args)
216
+
217
+ args = ["test/non_erb.conf", "#{server.config_path}/non_erb.conf"]
218
+ assert @server_app.shell.method_called?(:upload, :args => args)
219
+ end
220
+
221
+
222
+ def test_config_template_files
223
+ files =
224
+ Dir["#{Sunshine::ROOT}/templates/rainbows/*"].select{|f| File.file?(f)}
225
+ assert_equal files, @rainbows.config_template_files
226
+ end
227
+
228
+
229
+ def test_remote_dirs
230
+ server = @rainbows
231
+
232
+ dirs = server.send :remote_dirs
233
+
234
+ assert_dir_in dirs, server.pid
235
+ assert_dir_in dirs, server.config_file_path
236
+ assert_dir_in dirs, server.log_file(:stderr)
237
+ assert_dir_in dirs, server.log_file(:stdout)
238
+ end
239
+
240
+
241
+ def test_register_after_user_script
242
+ server = @rainbows
243
+
244
+ assert @app.method_called?(:after_user_script) # called on Server#init
245
+
246
+ @app.run_post_user_lambdas
247
+
248
+ server.each_server_app do |sa|
249
+
250
+ assert sa.scripts[:start].include?(server.start_cmd)
251
+ assert sa.scripts[:stop].include?(server.stop_cmd)
252
+ assert sa.scripts[:status].include?(server.status_cmd)
253
+ assert sa.scripts[:restart].include?(server.restart_cmd)
254
+
255
+ assert_equal server.port, sa.info[:ports][server.pid]
256
+ end
257
+ end
258
+
259
+
260
+ def test_pick_sudo
261
+ ds = @rainbows.app.server_apps.first.shell
262
+ assert_equal nil, @rainbows.send(:pick_sudo, ds)
263
+
264
+ @rainbows.sudo = true
265
+ assert_equal true, @rainbows.send(:pick_sudo, ds)
266
+
267
+ ds.sudo = true
268
+ @rainbows.sudo = false
269
+ assert_equal true, @rainbows.send(:pick_sudo, ds)
270
+
271
+ ds.sudo = "blah"
272
+ @rainbows.sudo = true
273
+ assert_equal "blah", @rainbows.send(:pick_sudo, ds)
274
+
275
+ @rainbows.sudo = "local"
276
+ assert_equal "local", @rainbows.send(:pick_sudo, ds)
277
+ end
278
+
279
+ ##
280
+ # Helper methods
281
+
282
+ def assert_dir_in arr, file
283
+ assert arr.include?(File.dirname(file))
284
+ end
285
+
286
+
287
+ def assert_server_init server=@server, user_config={}
288
+ config = {
289
+ :app => @app,
290
+ :target => @app,
291
+ :name => "server",
292
+ :pid => "#{@app.shared_path}/pids/server.pid",
293
+ :bin => "server",
294
+ :port => 80,
295
+ :processes => 1,
296
+ :server_name => nil,
297
+ :config_file => "server.conf",
298
+ :config_path => "#{@app.current_path}/daemons/server",
299
+ :config_template => "#{Sunshine::ROOT}/templates/server/*",
300
+ :stderr => "#{@app.log_path}/server_stderr.log",
301
+ :stdout => "#{@app.log_path}/server_stdout.log"
302
+ }.merge(user_config)
303
+
304
+ assert_equal config[:app], server.app
305
+ assert_equal config[:bin], server.bin
306
+ assert_equal config[:pid], server.pid
307
+ assert_equal config[:port], server.port
308
+ assert_equal config[:name], server.name
309
+ assert_equal config[:target], server.target
310
+ assert_equal config[:processes], server.processes
311
+ assert_equal config[:server_name], server.server_name
312
+
313
+ assert_equal config[:config_path], server.config_path
314
+ assert_equal config[:config_file], server.config_file
315
+ assert_equal config[:config_template], server.config_template
316
+
317
+
318
+ assert_equal config[:stderr], server.log_file(:stderr)
319
+ assert_equal config[:stdout], server.log_file(:stdout)
320
+
321
+ config_file_path = "#{config[:config_path]}/#{config[:config_file]}"
322
+ assert_equal config_file_path, server.config_file_path
323
+ end
324
+ end