X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Fdeploy.t;h=eb317758c5f69b33a10b44e34cb678fc28d09c51;hb=3aac91f35f319b3bf6bad743d956f037ba857012;hp=444bf26c173185c75b545ae73558244159efb951;hpb=8d6b1478d8fa6f7c76e313ee72a72d5eb4c24d03;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/deploy.t b/t/storage/deploy.t index 444bf26..eb31775 100644 --- a/t/storage/deploy.t +++ b/t/storage/deploy.t @@ -1,21 +1,25 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } +use DBIx::Class::Optional::Dependencies -skip_all_without => 'deploy'; + use strict; use warnings; use Test::More; use Test::Exception; -use lib qw(t/lib); use DBICTest; +use DBICTest::Util qw( slurp_bytes rm_rf ); +use DBIx::Class::_Util 'mkdir_p'; -BEGIN { - require DBIx::Class; - plan skip_all => - 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') - unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') -} +local $ENV{DBI_DSN}; -use File::Spec; -use Path::Class qw/dir/; +# this is how maint/gen_schema did it (connect() to force a storage +# instance, but no conninfo) +# there ought to be more code like this in the wild +like( + DBICTest::Schema->connect->deployment_statements('SQLite'), + qr/\bCREATE TABLE artist\b/i # ensure quoting *is* disabled +); lives_ok( sub { my $parse_schema = DBICTest->init_schema(no_deploy => 1); @@ -23,25 +27,57 @@ lives_ok( sub { $parse_schema->resultset("Artist")->all(); }, 'artist table deployed correctly' ); -my $schema = DBICTest->init_schema(); +my $schema = DBICTest->init_schema( quote_names => 1 ); -my $var = dir ("t/var/ddl_dir-$$"); -$var->mkpath unless -d $var; +my $var_dir = "t/var/ddl_dir-$$/"; +mkdir_p $var_dir unless -d $var_dir; -my $test_dir_1 = $var->subdir ('test1', 'foo', 'bar' ); -$test_dir_1->rmtree if -d $test_dir_1; -$schema->create_ddl_dir( undef, undef, $test_dir_1 ); +my $test_dir_1 = $var_dir . 'test1/foo/bar'; +rm_rf $test_dir_1 if -d $test_dir_1; +$schema->create_ddl_dir( [qw(SQLite MySQL)], 1, $test_dir_1 ); ok( -d $test_dir_1, 'create_ddl_dir did a make_path on its target dir' ); ok( scalar( glob $test_dir_1.'/*.sql' ), 'there are sql files in there' ); -TODO: { - local $TODO = 'we should probably add some tests here for actual deployability of the DDL?'; - ok( 0 ); +my $less = $schema->clone; +$less->unregister_source('BindType'); +$less->create_ddl_dir( [qw(SQLite MySQL)], 2, $test_dir_1, 1 ); + +for ( + [ SQLite => '"' ], + [ MySQL => '`' ], +) { + my $type = $_->[0]; + my $q = quotemeta($_->[1]); + + for my $f (map { $test_dir_1 . "/DBICTest-Schema-${_}-$type.sql" } qw(1 2) ) { + like ( + scalar slurp_bytes $f, + qr/CREATE TABLE ${q}track${q}/, + "Proper quoting in $f" + ); + } + + { + local $TODO = 'SQLT::Producer::MySQL has no knowledge of the mythical beast of quoting...' + if $type eq 'MySQL'; + + my $f = $test_dir_1 . "/DBICTest-Schema-1-2-$type.sql"; + like ( + scalar slurp_bytes $f, + qr/DROP TABLE ${q}bindtype_test${q}/, + "Proper quoting in diff $f" + ); + } +} + +{ + local $TODO = 'we should probably add some tests here for actual deployability of the DDL?'; + ok( 0 ); } END { - $var->rmtree; + rm_rf $var_dir; } done_testing;