Release commit for 0.07049
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_10informix_common.t
index 00832c3..6ebd0a2 100644 (file)
@@ -1,3 +1,6 @@
+use DBIx::Class::Schema::Loader::Optional::Dependencies
+    -skip_all_without => 'test_rdbms_informix';
+
 use strict;
 use warnings;
 use Test::More;
@@ -27,7 +30,7 @@ my $password = $ENV{DBICTEST_INFORMIX_PASS} || '';
 
 my ($schema, $extra_schema); # for cleanup in END for extra tests
 
-my $tester = dbixcsl_common_tests->new(
+dbixcsl_common_tests->new(
     vendor         => 'Informix',
     auto_inc_pk    => 'serial primary key',
     null           => '',
@@ -63,9 +66,9 @@ my $tester = dbixcsl_common_tests->new(
         numeric            => { data_type => 'numeric' },
         decimal            => { data_type => 'numeric' },
         dec                => { data_type => 'numeric' },
-       'numeric(6,3)'     => { data_type => 'numeric', size => [6,3] },
-       'decimal(6,3)'     => { data_type => 'numeric', size => [6,3] },
-       'dec(6,3)'         => { data_type => 'numeric', size => [6,3] },
+        'numeric(6,3)'     => { data_type => 'numeric', size => [6,3] },
+        'decimal(6,3)'     => { data_type => 'numeric', size => [6,3] },
+        'dec(6,3)'         => { data_type => 'numeric', size => [6,3] },
 
         # Boolean Type
         # XXX this should map to 'boolean'
@@ -144,7 +147,6 @@ my $tester = dbixcsl_common_tests->new(
                 });
 
                 my $dbh1 = $schema->storage->dbh;
-                my $dbh2 = $extra_schema->storage->dbh;
 
                 $dbh1->do(<<'EOF');
                     CREATE TABLE informix_loader_test4 (
@@ -162,6 +164,13 @@ EOF
                 $dbh1->do(<<'EOF');
 ALTER TABLE informix_loader_test5 ADD CONSTRAINT UNIQUE (four_id) CONSTRAINT loader_test5_uniq
 EOF
+
+                my $db1 = db_name($schema);
+
+                $dbh1->disconnect;
+
+                my $dbh2 = $extra_schema->storage->dbh;
+
                 $dbh2->do(<<'EOF');
                     CREATE TABLE informix_loader_test5 (
                         pk SERIAL PRIMARY KEY,
@@ -186,9 +195,10 @@ EOF
                     )
 EOF
 
-                my $db1 = db_name($schema);
                 my $db2 = db_name($extra_schema);
 
+                $dbh2->disconnect;
+
                 my $db1_moniker = join '', map ucfirst lc, split_name to_identifier $db1;
                 my $db2_moniker = join '', map ucfirst lc, split_name to_identifier $db2;
 
@@ -199,19 +209,20 @@ EOF
                             push @warns, $_[0] unless $_[0] =~ /\bcollides\b/
                                 || $_[0] =~ /unreferencable/;
                         };
-     
+
                         make_schema_at(
                             'InformixMultiDatabase',
                             {
                                 naming => 'current',
                                 db_schema => $db_schema,
-                                moniker_parts => [qw/database name/],
                                 dump_directory => EXTRA_DUMP_DIR,
                                 quiet => 1,
                             },
                             [ $dsn, $user, $password ],
                         );
 
+                        InformixMultiDatabase->storage->disconnect;
+
                         diag join "\n", @warns if @warns;
 
                         is @warns, 0;
@@ -226,7 +237,7 @@ EOF
                     my ($rsrc, $rs, $row, $rel_info, %uniqs);
 
                     lives_and {
-                        ok $rsrc = $test_schema->source("${db1_moniker}InformixLoaderTest4");
+                        ok $rsrc = $test_schema->source("InformixLoaderTest4");
                     } 'got source for table in database one';
 
                     is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
@@ -239,7 +250,7 @@ EOF
                         'column in database one';
 
                     lives_and {
-                        ok $rs = $test_schema->resultset("${db1_moniker}InformixLoaderTest4");
+                        ok $rs = $test_schema->resultset("InformixLoaderTest4");
                     } 'got resultset for table in database one';
 
                     lives_and {
@@ -273,7 +284,7 @@ EOF
                         'correct unique constraint in database one');
 
                     lives_and {
-                        ok $rsrc = $test_schema->source("${db2_moniker}InformixLoaderTest6");
+                        ok $rsrc = $test_schema->source("InformixLoaderTest6");
                     } 'got source for table in database two';
 
                     is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
@@ -286,7 +297,7 @@ EOF
                         'column in database two introspected correctly';
 
                     lives_and {
-                        ok $rs = $test_schema->resultset("${db2_moniker}InformixLoaderTest6");
+                        ok $rs = $test_schema->resultset("InformixLoaderTest6");
                     } 'got resultset for table in database two';
 
                     lives_and {
@@ -306,7 +317,7 @@ EOF
                         'relationship in database two';
 
                     lives_and {
-                        ok $rsrc = $test_schema->source("${db2_moniker}InformixLoaderTest7");
+                        ok $rsrc = $test_schema->source("InformixLoaderTest7");
                     } 'got source for table in database two';
 
                     %uniqs = try { $rsrc->unique_constraints };
@@ -322,14 +333,7 @@ EOF
             }
         },
     },
-);
-
-if( !$dsn ) {
-    $tester->skip_tests('You need to set the DBICTEST_INFORMIX_DSN, _USER, and _PASS environment variables');
-}
-else {
-    $tester->run_tests();
-}
+)->run_tests();
 
 sub db_name {
     my $schema = shift;
@@ -339,23 +343,37 @@ sub db_name {
     local $schema->loader->{schema} = $schema;
 
     return $schema->loader->_current_db;
+
+    $schema->storage->disconnect;
 }
 
 END {
     if (not $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) {
         if (my $dbh2 = try { $extra_schema->storage->dbh }) {
-            my $dbh1 = $schema->storage->dbh;
 
             try {
                 $dbh2->do('DROP TABLE informix_loader_test7');
                 $dbh2->do('DROP TABLE informix_loader_test6');
                 $dbh2->do('DROP TABLE informix_loader_test5');
+            }
+            catch {
+                die "Error dropping test tables: $_";
+            };
+
+            $dbh2->disconnect;
+        }
+
+        if (my $dbh1 = try { $schema->storage->dbh }) {
+
+            try {
                 $dbh1->do('DROP TABLE informix_loader_test5');
                 $dbh1->do('DROP TABLE informix_loader_test4');
             }
             catch {
                 die "Error dropping test tables: $_";
             };
+
+            $dbh1->disconnect;
         }
 
         rmtree EXTRA_DUMP_DIR;