Streamline connection codepath, fix $ENV{DBI_DSN} regression from d87929a4
[dbsrgits/DBIx-Class.git] / t / storage / deploy.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Exception;
6 use Path::Class qw/dir/;
7
8 use lib qw(t/lib);
9 use DBICTest;
10
11 BEGIN {
12   require DBIx::Class;
13   plan skip_all =>
14       'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy')
15     unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy')
16 }
17
18 local $ENV{DBI_DSN};
19
20 # this is how maint/gen_schema did it (connect() to force a storage
21 # instance, but no conninfo)
22 # there ought to be more code like this in the wild
23 like(
24   DBICTest::Schema->connect->deployment_statements('SQLite'),
25   qr/\bCREATE TABLE\b/i
26 );
27
28 lives_ok( sub {
29     my $parse_schema = DBICTest->init_schema(no_deploy => 1);
30     $parse_schema->deploy({},'t/lib/test_deploy');
31     $parse_schema->resultset("Artist")->all();
32 }, 'artist table deployed correctly' );
33
34 my $schema = DBICTest->init_schema();
35
36 my $var = dir ("t/var/ddl_dir-$$");
37 $var->mkpath unless -d $var;
38
39 my $test_dir_1 = $var->subdir ('test1', 'foo', 'bar' );
40 $test_dir_1->rmtree if -d $test_dir_1;
41 $schema->create_ddl_dir( undef, undef, $test_dir_1 );
42
43 ok( -d $test_dir_1, 'create_ddl_dir did a make_path on its target dir' );
44 ok( scalar( glob $test_dir_1.'/*.sql' ), 'there are sql files in there' );
45
46 {
47   local $TODO = 'we should probably add some tests here for actual deployability of the DDL?';
48   ok( 0 );
49 }
50
51 END {
52   $var->rmtree;
53 }
54
55 done_testing;