root/Log-Dispatch-DBI/trunk/t/02_dbh.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 log (
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         dbh => $dbh,
23     );
24     ok $log->log(level => 'emergency', message => 'something BAD happened');
25 }
26
27 {
28     my $sth = $dbh->prepare('SELECT * FROM log');
29     $sth->execute;
30
31     while (my $data = $sth->fetchrow_arrayref) {
32         is $data->[0], 'emergency', 'level';
33         is $data->[1], 'something BAD happened', 'message';
34     }
35 }
36
Note: See TracBrowser for help on using the browser.