1 require File.dirname(__FILE__) + '/helper'
6 raise "You forgot to stub fork"
10 raise "You forgot to stub exec"
15 class TestProcessChild < Test::Unit::TestCase
17 @p = God::Process.new(:name => 'foo')
18 @p.stubs(:test).returns true # so we don't try to mkdir_p
19 Process.stubs(:detach) # because we stub fork
24 def test_valid_should_return_true_if_auto_daemonized_and_log
31 def test_valid_should_return_true_if_auto_daemonized_and_no_stop
38 def test_valid_should_return_true_if_uid_exists
46 def test_valid_should_return_true_if_uid_does_not_exists
56 def test_valid_should_return_true_if_gid_exists
64 def test_valid_should_return_true_if_gid_does_not_exists
75 class TestProcessDaemon < Test::Unit::TestCase
77 @p = God::Process.new(:name => 'foo', :pid_file => 'blah.pid')
78 @p.stubs(:test).returns true # so we don't try to mkdir_p
79 Process.stubs(:detach) # because we stub fork
84 def test_valid_should_return_false_if_no_start
90 def test_valid_should_return_false_if_self_daemonized_and_no_stop
98 def test_valid_should_return_false_if_self_daemonized_and_log
109 def test_default_pid_file
110 assert_equal File.join(God.pid_file_directory, 'foo.pid'), @p.default_pid_file
114 # These actually excercise call_action in the back at this point - Kev
116 def test_call_action_with_string_should_fork_exec
117 @p.start = "do something"
118 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
120 Process.expects(:waitpid)
121 @p.call_action(:start)
124 def test_call_action_with_lambda_should_call
125 cmd = lambda { puts "Hi" }
128 @p.call_action(:start)
131 def test_call_action_without_pid_should_write_pid
132 # Only for start, restart
133 [:start, :restart].each do |action|
134 @p = God::Process.new(:name => 'foo')
135 @p.stubs(:test).returns true
136 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
138 Process.expects(:waitpid)
139 File.expects(:open).with(@p.default_pid_file, 'w')
140 @p.send("#{action}=", "run")
141 @p.call_action(action)
145 def test_call_action_should_not_write_pid_for_stop
147 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
149 Process.expects(:waitpid)
150 File.expects(:open).times(0)
152 @p.call_action(:stop)
155 def test_call_action_should_mkdir_p_if_pid_file_dir_existence_test_fails
157 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
159 Process.expects(:waitpid)
160 @p.expects(:test).returns(false, true)
161 FileUtils.expects(:mkdir_p).with(God.pid_file_directory)
163 @p.start = "starting"
164 @p.call_action(:start)
167 # start!/stop!/restart!
169 def test_start_stop_restart_bang
170 [:start, :stop, :restart].each do |x|
171 @p.expects(:call_action).with(x)