File: 99postgres.t

package info (click to toggle)
libapache-session-perl 1.94-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 448 kB
  • sloc: perl: 1,514; makefile: 2
file content (108 lines) | stat: -rw-r--r-- 2,629 bytes parent folder | download | duplicates (5)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

use Test::More;
use Test::Deep;

plan skip_all => "Not running RDBM tests without APACHE_SESSION_MAINTAINER=1"
  unless ($ENV{APACHE_SESSION_MAINTAINER} || $ENV{TRAVIS});
plan skip_all => "Optional modules (DBD::Pg, DBI) not installed"
  unless eval {
               require DBD::Pg;
               require DBI;
              };

plan tests => 13;

my $package = 'Apache::Session::Postgres';
use_ok $package;

my $session = {};

my ($dbname, $user, $pass) = ('test', 'postgres', '');
my $dsn = "dbi:Pg:database=$dbname";
{

    my $dbh1 = DBI->connect($dsn, $user, $pass, {RaiseError => 1, AutoCommit => 1, PrintError=>0, PrintWarn=>0,});
    foreach my $table (qw/sessions s/) {
        eval { $dbh1->do("DROP TABLE $table", {RaiseError => 0, PrintError=>0, PrintWarn=>0,});};
        $dbh1->do(<<"EOT");
 CREATE TABLE $table (
    id char(32) not null primary key,
    a_session text
 )
EOT
    }
}


tie %{$session}, $package, undef, {
    DataSource => "dbi:Pg:dbname=$dbname",
    UserName   => $user, 
    Password   => $pass,
    Commit     => 1
};

ok tied(%{$session}), 'session tied';

ok exists($session->{_session_id}), 'session id exists';

my $id = $session->{_session_id};

my $foo = $session->{foo} = 'bar';
my $baz = $session->{baz} = ['tom', 'dick', 'harry'];

untie %{$session};
undef $session;
$session = {};

tie %{$session}, $package, $id, {
    DataSource => "dbi:Pg:dbname=$dbname",
    UserName   => $user, 
    Password   => $pass,
    Commit   => 1
};

ok tied(%{$session}), 'session tied';

is $session->{_session_id}, $id, 'id retrieved matches one stored';

cmp_deeply $session->{foo}, $foo, "Foo matches";
cmp_deeply $session->{baz}, $baz, "Baz matches";

untie %{$session};
undef $session;
$session = {};

tie %{$session}, $package, undef, {
    DataSource => "dbi:Pg:dbname=$dbname",
    UserName   => $user, 
    Password   => $pass,
    Commit   => 1,
    TableName => 's'
};

ok tied(%{$session}), 'session tied';

ok exists($session->{_session_id}), 'session id exists';

untie %{$session};
undef $session;
$session = {};

my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", $user, $pass, {RaiseError => 1, AutoCommit => 0});

tie %{$session}, $package, $id, {
    Handle => $dbh,
    Commit => 0,
};

ok tied(%{$session}), 'session tied';

is $session->{_session_id}, $id, 'id retrieved matches one stored';

cmp_deeply $session->{foo}, $foo, "Foo matches";
cmp_deeply $session->{baz}, $baz, "Baz matches";

tied(%{$session})->delete;
untie %{$session};
$dbh->commit;
$dbh->disconnect;