1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
use strict;
use File::Spec;
use Test::More;
use CGI::Session::Test::Default;
for ( "DBI", "DBD::SQLite", "Storable", "MIME::Base64" ) {
eval "require $_";
if ( $@ ) {
plan(skip_all=>"$_ is NOT available");
exit(0);
}
}
my $dir_name = File::Spec->tmpdir();
my $file_name= File::Spec->catfile($dir_name, 'sessions.sqlt');
my %dsn = (
DataSource => "dbi:SQLite:dbname=$file_name",
TableName => 'sessions'
);
my $dbh = DBI->connect($dsn{DataSource}, '', '', {RaiseError=>0, PrintError=>0, sqlite_handle_binary_nulls=>1});
unless ( $dbh ) {
plan(skip_all=>"Couldn't establish connection with the server. " . DBI->errstr);
exit(0);
}
my ($count) = $dbh->selectrow_array("SELECT COUNT(*) FROM $dsn{TableName}");
unless ( defined $count ) {
unless( $dbh->do(qq|
CREATE TABLE $dsn{TableName} (
id CHAR(32) NOT NULL PRIMARY KEY,
a_session BLOB NOT NULL
)|) ) {
plan(skip_all=>$dbh->errstr);
exit(0);
}
}
my $t = CGI::Session::Test::Default->new(
dsn => "driver:sqlite;serializer:storable",
args=>{Handle=>$dbh, TableName=>$dsn{TableName}});
plan tests => $t->number_of_tests;
TODO: {
# local $TODO = "SQLite doesn't work with Storable yet.";
$t->run();
}
unlink $file_name;
|