"Fossies" - the Fresh Open Source Software Archive

Member "Apache-Session-1.93/t/99postgres.t" (24 Dec 2012, 2629 Bytes) of package /linux/www/Apache-Session-1.93.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 use Test::More;
    3 use Test::Deep;
    4 
    5 plan skip_all => "Not running RDBM tests without APACHE_SESSION_MAINTAINER=1"
    6   unless ($ENV{APACHE_SESSION_MAINTAINER} || $ENV{TRAVIS});
    7 plan skip_all => "Optional modules (DBD::Pg, DBI) not installed"
    8   unless eval {
    9                require DBD::Pg;
   10                require DBI;
   11               };
   12 
   13 plan tests => 13;
   14 
   15 my $package = 'Apache::Session::Postgres';
   16 use_ok $package;
   17 
   18 my $session = {};
   19 
   20 my ($dbname, $user, $pass) = ('test', 'postgres', '');
   21 my $dsn = "dbi:Pg:database=$dbname";
   22 {
   23 
   24     my $dbh1 = DBI->connect($dsn, $user, $pass, {RaiseError => 1, AutoCommit => 1, PrintError=>0, PrintWarn=>0,});
   25     foreach my $table (qw/sessions s/) {
   26         eval { $dbh1->do("DROP TABLE $table", {RaiseError => 0, PrintError=>0, PrintWarn=>0,});};
   27         $dbh1->do(<<"EOT");
   28  CREATE TABLE $table (
   29     id char(32) not null primary key,
   30     a_session text
   31  )
   32 EOT
   33     }
   34 }
   35 
   36 
   37 tie %{$session}, $package, undef, {
   38     DataSource => "dbi:Pg:dbname=$dbname",
   39     UserName   => $user, 
   40     Password   => $pass,
   41     Commit     => 1
   42 };
   43 
   44 ok tied(%{$session}), 'session tied';
   45 
   46 ok exists($session->{_session_id}), 'session id exists';
   47 
   48 my $id = $session->{_session_id};
   49 
   50 my $foo = $session->{foo} = 'bar';
   51 my $baz = $session->{baz} = ['tom', 'dick', 'harry'];
   52 
   53 untie %{$session};
   54 undef $session;
   55 $session = {};
   56 
   57 tie %{$session}, $package, $id, {
   58     DataSource => "dbi:Pg:dbname=$dbname",
   59     UserName   => $user, 
   60     Password   => $pass,
   61     Commit   => 1
   62 };
   63 
   64 ok tied(%{$session}), 'session tied';
   65 
   66 is $session->{_session_id}, $id, 'id retrieved matches one stored';
   67 
   68 cmp_deeply $session->{foo}, $foo, "Foo matches";
   69 cmp_deeply $session->{baz}, $baz, "Baz matches";
   70 
   71 untie %{$session};
   72 undef $session;
   73 $session = {};
   74 
   75 tie %{$session}, $package, undef, {
   76     DataSource => "dbi:Pg:dbname=$dbname",
   77     UserName   => $user, 
   78     Password   => $pass,
   79     Commit   => 1,
   80     TableName => 's'
   81 };
   82 
   83 ok tied(%{$session}), 'session tied';
   84 
   85 ok exists($session->{_session_id}), 'session id exists';
   86 
   87 untie %{$session};
   88 undef $session;
   89 $session = {};
   90 
   91 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", $user, $pass, {RaiseError => 1, AutoCommit => 0});
   92 
   93 tie %{$session}, $package, $id, {
   94     Handle => $dbh,
   95     Commit => 0,
   96 };
   97 
   98 ok tied(%{$session}), 'session tied';
   99 
  100 is $session->{_session_id}, $id, 'id retrieved matches one stored';
  101 
  102 cmp_deeply $session->{foo}, $foo, "Foo matches";
  103 cmp_deeply $session->{baz}, $baz, "Baz matches";
  104 
  105 tied(%{$session})->delete;
  106 untie %{$session};
  107 $dbh->commit;
  108 $dbh->disconnect;