-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path55_session_factory.t
56 lines (43 loc) · 1.2 KB
/
55_session_factory.t
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
# $Id: 55_session_factory.t,v 1.1 2004/02/24 12:38:29 miyagawa Exp $
#
# Tatsuhiko Miyagawa <miyagawa@livedoor.jp>
# Livedoor, Co.,Ltd.
#
use strict;
use Test::More;
plan tests => 4;
fake_modules("Sledge::Session::MySQL", "Sledge::Session::Pg", "Sledge::Session::SQLite");
use lib "t/lib";
package Mock::Pages;
use base qw(Sledge::TestPages);
use Sledge::Session::DBIFactory;
sub create_session {
my $self = shift;
return Sledge::Session::DBIFactory->new($self, @_);
}
package main;
do_test("dbi:mysql:test", 'Sledge::Session::MySQL');
do_test("dbi:Pg:db=foo", 'Sledge::Session::Pg');
do_test("dbi:SQLite:db=foo", 'Sledge::Session::SQLite');
do_test("dbi:blahblah", 'blahblah at .*/DBIFactory\.pm');
sub fake_modules {
for my $module (@_) {
no strict 'refs';
@{"$module\::ISA"} = qw(Mock::Session);
(my $f = $module) =~ s!::!/!g;
$INC{"$f.pm"} = __PACKAGE__;
}
}
sub do_test {
my($dsn, $class) = @_;
my $dummy = $Mock::Pages::DATASOURCE;
local $Mock::Pages::DATASOURCE = [ $dsn, "blah", "blah" ];
my $p = Mock::Pages->new();
eval { $p->dispatch("foo") };
like $@, qr/$class/, "$dsn => $class";
}
package Mock::Session;
sub new {
my $class = shift;
die $class;
}