root/Log-Dispatch-DBI/trunk/t/01_csv.t

Revision 353 (checked in by miyagawa, 19 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 use strict;
2 use Test::More tests => 3;
3
4 use DBI;
5 use File::Temp qw(tempdir);
6 use Log::Dispatch::DBI;
7
8 my $temp = tempdir(CLEANUP => 1);
9 my $dbh = DBI->connect("dbi:CSV:f_dir=$temp") or die $DBI::errstr;
10 $dbh->do(<<'SQL');
11 CREATE TABLE logging (
12     level VARCHAR(9) NOT NULL,
13     message text NOT NULL
14 )
15 SQL
16     ;
17
18 {
19     my $log = Log::Dispatch::DBI->new(
20         name => 'dbi',
21         min_level => 'info',
22         datasource => "dbi:CSV:f_dir=$temp",
23         table => 'logging',
24     );
25     ok $log->log(level => 'emergency', message => 'something BAD happened');
26 }
27
28 {
29     my $sth = $dbh->prepare('SELECT * FROM logging');
30     $sth->execute;
31
32     while (my $data = $sth->fetchrow_arrayref) {
33         is $data->[0], 'emergency', 'level';
34         is $data->[1], 'something BAD happened', 'message';
35     }
36 }
37
Note: See TracBrowser for help on using the browser.