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
20 @p.stubs(:test).returns true # so we don't try to mkdir_p
21 Process.stubs(:detach) # because we stub fork
26 def test_valid_should_return_true_if_auto_daemonized_and_log
33 def test_valid_should_return_true_if_auto_daemonized_and_no_stop
40 def test_valid_should_return_true_if_uid_exists
48 def test_valid_should_return_true_if_uid_does_not_exists
58 def test_valid_should_return_true_if_gid_exists
66 def test_valid_should_return_true_if_gid_does_not_exists
78 def test_call_action_should_write_pid
79 # Only for start, restart
80 [:start, :restart].each do |action|
81 @p.stubs(:test).returns true
82 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
84 Process.expects(:waitpid)
85 File.expects(:open).with(@p.default_pid_file, 'w')
86 @p.send("#{action}=", "run")
87 @p.call_action(action)
92 ###############################################################################
96 ###############################################################################
98 class TestProcessDaemon < Test::Unit::TestCase
101 @p = God::Process.new
103 @p.pid_file = 'blah.pid'
104 @p.stubs(:test).returns true # so we don't try to mkdir_p
105 Process.stubs(:detach) # because we stub fork
110 def test_alive_should_call_system_process_exists
111 File.expects(:read).with('blah.pid').returns('1234')
112 System::Process.any_instance.expects(:exists?).returns(false)
116 def test_alive_should_return_false_if_no_such_file
117 File.expects(:read).with('blah.pid').raises(Errno::ENOENT)
123 def test_valid_should_return_false_if_no_start
131 def test_valid_should_return_false_if_self_daemonized_and_no_stop
142 def test_default_pid_file
143 assert_equal File.join(God.pid_file_directory, 'foo.pid'), @p.default_pid_file
147 # These actually excercise call_action in the back at this point - Kev
149 def test_call_action_with_string_should_call_system
150 @p.start = "do something"
152 Process.expects(:waitpid)
153 @p.call_action(:start)
156 def test_call_action_with_lambda_should_call
157 cmd = lambda { puts "Hi" }
160 @p.call_action(:start)
163 def test_call_action_with_invalid_command_class_should_raise
169 assert_raise NotImplementedError do
170 @p.call_action(:start)
174 # start!/stop!/restart!
176 def test_start_stop_restart_bang
177 [:start, :stop, :restart].each do |x|
178 @p.expects(:call_action).with(x)