Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / storage / dbi_env.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
c1807ed5 3use strict;
4use warnings;
c0329273 5
c1807ed5 6use DBICTest;
7use Test::More;
8use Test::Exception;
37b5ab51 9use DBIx::Class::_Util 'sigwarn_silencer';
c1807ed5 10
11BEGIN { delete @ENV{qw(DBI_DSN DBI_DRIVER)} }
12
8d6b1478 13$ENV{DBICTEST_LOCK_HOLDER} = -1;
c1807ed5 14
8d6b1478 15# pre-populate
16my $schema = DBICTest->init_schema(sqlite_use_file => 1);
c1807ed5 17
18my $dbname = DBICTest->_sqlite_dbname(sqlite_use_file => 1);
19
20sub count_sheep {
21 my $schema = shift;
37b5ab51 22
23 local $SIG{__WARN__} = sigwarn_silencer(
24 qr/
25 \QThis version of DBIC does not yet seem to supply a driver for your particular RDBMS\E
26 |
27 \QUnable to extract a driver name from connect info\E
28 |
29 \QYour storage class (DBIx::Class::Storage::DBI) does not set sql_limit_dialect\E
30 /x
31 );
32
c1807ed5 33 scalar $schema->resultset('Artist')->search( { name => "Exploding Sheep" } )
34 ->all;
35}
36
37$schema = DBICTest::Schema->connect("dbi::$dbname");
38throws_ok { count_sheep($schema) } qr{I can't work out what driver to use},
39 'Driver in DSN empty';
40isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
41
42$schema = DBICTest::Schema->connect("dbi:Test_NonExistant_DBD:$dbname");
43throws_ok { count_sheep($schema) }
44 qr{Can't locate DBD/Test_NonExistant_DBD\.pm in \@INC},
45 "Driver class doesn't exist";
46isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
47
48$ENV{DBI_DSN} = "dbi::$dbname";
49$schema = DBICTest::Schema->connect;
50throws_ok { count_sheep($schema) } qr{I can't work out what driver to use},
51 "Driver class not defined in DBI_DSN either.";
52isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
53
54$ENV{DBI_DSN} = "dbi:Test_NonExistant_DBD2:$dbname";
55$schema = DBICTest::Schema->connect;
56throws_ok { count_sheep($schema) }
57 qr{Can't locate DBD/Test_NonExistant_DBD2\.pm in \@INC},
58 "Driver class defined in DBI_DSN doesn't exist";
59isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
60
61$ENV{DBI_DSN} = "dbi::$dbname";
62$ENV{DBI_DRIVER} = 'Test_NonExistant_DBD3';
63$schema = DBICTest::Schema->connect;
64throws_ok { count_sheep($schema) }
65 qr{Can't locate DBD/Test_NonExistant_DBD3\.pm in \@INC},
66 "Driver class defined in DBI_DRIVER doesn't exist";
67isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
68
69$ENV{DBI_DSN} = "dbi:Test_NonExistant_DBD4:$dbname";
70$schema = DBICTest::Schema->connect;
71throws_ok { count_sheep($schema) }
72qr{Can't locate DBD/Test_NonExistant_DBD4\.pm in \@INC},
73 "Driver class defined in DBI_DSN doesn't exist";
74isa_ok $schema->storage, 'DBIx::Class::Storage::DBI';
75
76delete @ENV{qw(DBI_DSN DBI_DRIVER)};
77
78$schema = DBICTest::Schema->connect("dbi:SQLite:$dbname");
79lives_ok { count_sheep($schema) } 'SQLite passed to connect_info';
80isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
81
e4328872 82$schema = DBICTest::Schema->connect("dbi:SQLite(ReadOnly=1):$dbname");
83lives_ok { count_sheep($schema) } 'SQLite passed to connect_info despite extra arguments present';
84isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
85
c1807ed5 86$ENV{DBI_DRIVER} = 'SQLite';
87$schema = DBICTest::Schema->connect("dbi::$dbname");
88lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER';
89isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
90
442cb03d 91delete $ENV{DBI_DRIVER};
c1807ed5 92$ENV{DBI_DSN} = "dbi:SQLite:$dbname";
93$schema = DBICTest::Schema->connect;
94lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN';
95isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
96
97$ENV{DBI_DRIVER} = 'SQLite';
98$schema = DBICTest::Schema->connect;
99lives_ok { count_sheep($schema) } 'SQLite in DBI_DSN (and DBI_DRIVER)';
100isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
101
102$ENV{DBI_DSN} = "dbi::$dbname";
103$ENV{DBI_DRIVER} = 'SQLite';
104$schema = DBICTest::Schema->connect;
105lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER (not DBI_DSN)';
106isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite';
107
37b5ab51 108# make sure that dynamically setting DBI_DSN post-connect works
109{
110 local $ENV{DBI_DSN};
111
112 my $s = DBICTest::Schema->connect();
113
114 throws_ok {
115 $s->storage->ensure_connected
116 } qr/You did not provide any connection_info/,
117 'sensible exception on empty conninfo connect';
118
119 $ENV{DBI_DSN} = 'dbi:SQLite::memory:';
120
121 lives_ok { $s->storage->ensure_connected } 'Second connection attempt worked';
122 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );
123}
124
c1807ed5 125done_testing;