File: 99dbfilestore.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 (79 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download | duplicates (6)
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
use Test::More;
use Test::Exception;
use File::Temp qw[tempdir];
use Cwd qw[getcwd];

plan skip_all => "Optional module (DB_File) not installed"
  unless eval {
               require DB_File;
              };

my $package = 'Apache::Session::Store::DB_File';

plan tests => 13;

use_ok $package;
use_ok 'DB_File';
can_ok $package, qw[new insert materialize remove];

my $origdir = getcwd;
my $tempdir = tempdir( DIR => '.', CLEANUP => 1 );
chdir( $tempdir );

my $serial  = '12345';
my $id      = 'test1';
my $dbfile  = 'foo.dbm';
my $session = {
    serialized => $serial,
    data       => {
                   _session_id => $id,
                  },
    args       => {
                   FileName => $dbfile,
                  },
};

my $store = $package->new;
isa_ok $store, $package;

my $i_ret = $store->insert($session);
is( $i_ret, $serial, "insert() returned value of serialized" );

ok( -e $dbfile, 'dbm file exists' );

undef $store;

$store = $package->new;
isa_ok $store, $package;

$session->{serialized} = undef;
lives_ok {
    $store->materialize($session)
} 'materialize did not die';
is( $session->{serialized}, $serial, "materialized session is correct" );

my $new_serial = 'hi';
$session->{serialized} = $new_serial;
my $u_ret = $store->update($session);
is( $u_ret, $new_serial, "update() returned value of new serialized" );

undef $store;

my %hash;
tie %hash, 'DB_File', $dbfile;

is( $hash{$id}, $new_serial, "dbm file updated correctly" );

$store = $package->new;
isa_ok $store, $package;
$store->remove($session);

dies_ok {
    $store->materialize($session);
} "Can't materialize removed session";

undef $store;
untie %hash;
undef %hash;

chdir( $origdir );