Class: TestLogFile

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_util/logfile.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) test_append



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'test/test_util/logfile.rb', line 40

def test_append
  file = File.expand_path('../data/log/foo/2003/08.log',
    File.dirname(__FILE__))
  begin
    ODDB::LogFile.append(:foo, ';foobar', Time.local(2003,8,21,19,32,10))
    assert(File.exist?(file), "Missing Logfile: #{file}")
    expected = "2003-08-21 19:32:10 CEST;foobar\n"
    assert_equal(expected, File.read(file))
    ODDB::LogFile.append(:foo, ';barbaz', Time.utc(2003,8,21,10,02,25))
    expected << "2003-08-21 10:02:25 GMT;barbaz\n"
    assert_equal(expected, File.read(file))
  ensure
    if(File.exist?(file))
      File.delete(file) 
      Dir.rmdir(File.dirname(file))
    end
  end
end

- (Object) test_create_dir



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'test/test_util/logfile.rb', line 25

def test_create_dir
  file = File.expand_path('../data/log/foo/2003/08.log',
    File.dirname(__FILE__))
  begin
    ODDB::LogFile.append(:foo, ';foobar', Time.local(2003,8,21,19,32,10))
    assert(File.exist?(file), "Missing Logfile: #{file}")
    expected = "2003-08-21 19:32:10 CEST;foobar\n"
    assert_equal(expected, File.read(file))
  ensure
    if(File.exist?(file))
      File.delete(file) 
      Dir.rmdir(File.dirname(file))
    end
  end
end

- (Object) test_filename



17
18
19
20
21
22
23
24
# File 'test/test_util/logfile.rb', line 17

def test_filename
  expected = File.expand_path('../data/log/foo/2003/08.log',
    File.dirname(__FILE__))
  res = ODDB::LogFile.filename(:foo, Date.new(2003,8,21))
  assert_equal(expected, res)
  res = ODDB::LogFile.filename(:foo, Time.local(2003,8,21))
  assert_equal(expected, res)
end

- (Object) test_read



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'test/test_util/logfile.rb', line 58

def test_read
  file = File.expand_path('../data/log/foo/2003/08.log',
    File.dirname(__FILE__))
  begin
    ODDB::LogFile.append(:foo, ';foobar', Time.local(2003,8,21,19,32,10))
    assert(File.exist?(file), "Missing Logfile: #{file}")
    expected = "2003-08-21 19:32:10 CEST;foobar\n"
    assert_equal(expected, ODDB::LogFile.read(:foo, Date.new(2003,8)))
  ensure
    if(File.exist?(file))
      File.delete(file) 
      Dir.rmdir(File.dirname(file))
    end
  end
end