god binary status, log, terminate, logging system improvements
[god.git] / test / test_logger.rb
blob47c7da320418234b01fedbcf2aea0e5f4bae08fa
1 require File.dirname(__FILE__) + '/helper'
3 class TestLogger < Test::Unit::TestCase
4   def setup
5     @log = God::Logger.new
6   end
7   
8   # log
9   
10   def test_log
11     @log.expects(:info).with("qux")
12     
13     no_stdout do
14       @log.log(stub(:name => 'foo'), :info, "qux")
15     end
16     
17     assert_equal 1, @log.logs.size
18     assert_instance_of Time, @log.logs['foo'][0][0]
19     assert_match /qux/, @log.logs['foo'][0][1]
20   end
21   
22   # watch_log_since
23   
24   def test_watch_log_since
25     t1 = Time.now
26     
27     no_stdout do
28       @log.log(stub(:name => 'foo'), :info, "one")
29       @log.log(stub(:name => 'foo'), :info, "two")
30     end
31     
32     assert_match /one.*two/m, @log.watch_log_since('foo', t1)
33     
34     t2 = Time.now
35     
36     no_stdout do
37       @log.log(stub(:name => 'foo'), :info, "three")
38     end
39     
40     out = @log.watch_log_since('foo', t2)
41     
42     assert_no_match /one/, out
43     assert_no_match /two/, out
44     assert_match /three/, out
45   end
46   
47   # regular methods
48   
49   def test_fatal
50     no_stdout do
51       @log.fatal('foo')
52     end
53     assert_equal 0, @log.logs.size
54   end
55 end