Convert the tests with multiple DBDs to new optdeps system
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_08sqlanywhere_common.t
index d5353f8..da9837b 100644 (file)
@@ -4,6 +4,7 @@ use Test::More;
 use Test::Exception;
 use Try::Tiny;
 use File::Path 'rmtree';
+use DBIx::Class::Optional::Dependencies;
 use DBIx::Class::Schema::Loader 'make_schema_at';
 use Scope::Guard ();
 
@@ -19,31 +20,40 @@ use constant EXTRA_DUMP_DIR => "$tdir/sqlanywhere_extra_dump";
 #
 # Setting them to zero is preferred.
 
-my $dbd_sqlanywhere_dsn      = $ENV{DBICTEST_SQLANYWHERE_DSN} || '';
-my $dbd_sqlanywhere_user     = $ENV{DBICTEST_SQLANYWHERE_USER} || '';
-my $dbd_sqlanywhere_password = $ENV{DBICTEST_SQLANYWHERE_PASS} || '';
+my %env2optdep = map { $_ => lc "test_rdbms_$_" } qw(SQLANYWHERE SQLANYWHERE_ODBC);
+
+plan skip_all => 'requirements not satisfied:  ' . (join '  OR  ', map
+    { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
+    values %env2optdep
+) unless scalar grep
+    { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) }
+    values %env2optdep
+;
+
+my %dsns;
+for my $type (keys %env2optdep) {
+    my %conninfo;
+    @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS);
+    next unless $conninfo{dsn};
+
+    my $dep_group = $env2optdep{$type};
+    if (!DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for($dep_group)) {
+        diag "Testing with DBICTEST_${type}_DSN needs " . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for($dep_group);
+        next;
+    }
 
-my $odbc_dsn      = $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN} || '';
-my $odbc_user     = $ENV{DBICTEST_SQLANYWHERE_ODBC_USER} || '';
-my $odbc_password = $ENV{DBICTEST_SQLANYWHERE_ODBC_PASS} || '';
+    $dsns{$type} = \%conninfo;
+}
 
 my ($schema, $schemas_created); # for cleanup in END for extra tests
 
 my $tester = dbixcsl_common_tests->new(
     vendor      => 'SQLAnywhere',
     auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY',
-    connect_info => [ ($dbd_sqlanywhere_dsn ? {
-            dsn         => $dbd_sqlanywhere_dsn,
-            user        => $dbd_sqlanywhere_user,
-            password    => $dbd_sqlanywhere_password,
-        } : ()),
-        ($odbc_dsn ? {
-            dsn         => $odbc_dsn,
-            user        => $odbc_user,
-            password    => $odbc_password,
-        } : ()),
-    ],
+    connect_info => [ map { $dsns{$_} } sort keys %dsns ],
     loader_options => { preserve_case => 1 },
+    default_is_deferrable => 1,
+    default_on_clause => 'RESTRICT',
     data_types  => {
         # http://infocenter.sybase.com/help/topic/com.sybase.help.sqlanywhere.11.0.1/dbreference_en11/rf-datatypes.html
         #
@@ -144,12 +154,42 @@ my $tester = dbixcsl_common_tests->new(
         'ntext'        => { data_type => 'ntext' },
     },
     extra => {
-        count => 30 * 2,
+        create => [
+            # 4 through 8 are used for the multi-schema tests
+            q{
+                create table sqlanywhere_loader_test9 (
+                    id int identity not null primary key
+                )
+            },
+            q{
+                create table sqlanywhere_loader_test10 (
+                    id int identity not null primary key,
+                    nine_id int,
+                    foreign key (nine_id) references sqlanywhere_loader_test9(id)
+                        on delete cascade on update set null
+                )
+            },
+        ],
+        drop  => [ qw/sqlanywhere_loader_test9 sqlanywhere_loader_test10/ ],
+        count => 4 + 30 * 2,
         run => sub {
             SKIP: {
                 $schema  = $_[0];
                 my $self = $_[3];
 
+                # test on delete/update fk clause introspection
+                ok ((my $rel_info = $schema->source('SqlanywhereLoaderTest10')->relationship_info('nine')),
+                    'got rel info');
+
+                is $rel_info->{attrs}{on_delete}, 'CASCADE',
+                    'ON DELETE clause introspected correctly';
+
+                is $rel_info->{attrs}{on_update}, 'SET NULL',
+                    'ON UPDATE clause introspected correctly';
+
+                is $rel_info->{attrs}{is_deferrable}, 1,
+                    'is_deferrable defaults to 1';
+
                 my $connect_info = [@$self{qw/dsn user password/}];
 
                 my $dbh = $schema->storage->dbh;
@@ -230,7 +270,6 @@ EOF
                             {
                                 naming => 'current',
                                 db_schema => $db_schema,
-                                moniker_parts => [qw/schema name/],
                                 dump_directory => EXTRA_DUMP_DIR,
                                 quiet => 1,
                             },
@@ -249,7 +288,7 @@ EOF
                     } 'connected test schema';
 
                     lives_and {
-                        ok $rsrc = $test_schema->source('DbicslTest1SqlanywhereLoaderTest4');
+                        ok $rsrc = $test_schema->source('SqlanywhereLoaderTest4');
                     } 'got source for table in schema one';
 
                     is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
@@ -262,7 +301,7 @@ EOF
                         'column in schema one';
 
                     lives_and {
-                        ok $rs = $test_schema->resultset('DbicslTest1SqlanywhereLoaderTest4');
+                        ok $rs = $test_schema->resultset('SqlanywhereLoaderTest4');
                     } 'got resultset for table in schema one';
 
                     lives_and {
@@ -296,7 +335,7 @@ EOF
                         'correct unique constraint in schema one');
 
                     lives_and {
-                        ok $rsrc = $test_schema->source('DbicslTest2SqlanywhereLoaderTest6');
+                        ok $rsrc = $test_schema->source('SqlanywhereLoaderTest6');
                     } 'got source for table in schema two';
 
                     is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
@@ -309,7 +348,7 @@ EOF
                         'column in schema two introspected correctly';
 
                     lives_and {
-                        ok $rs = $test_schema->resultset('DbicslTest2SqlanywhereLoaderTest6');
+                        ok $rs = $test_schema->resultset('SqlanywhereLoaderTest6');
                     } 'got resultset for table in schema two';
 
                     lives_and {
@@ -329,7 +368,7 @@ EOF
                         'relationship in schema two';
 
                     lives_and {
-                        ok $rsrc = $test_schema->source('DbicslTest2SqlanywhereLoaderTest7');
+                        ok $rsrc = $test_schema->source('SqlanywhereLoaderTest7');
                     } 'got source for table in schema two';
 
                     %uniqs = try { $rsrc->unique_constraints };
@@ -343,22 +382,22 @@ EOF
                         'correct unique constraint in schema two');
 
                     lives_and {
-                        ok $test_schema->source('DbicslTest2SqlanywhereLoaderTest6')
+                        ok $test_schema->source('SqlanywhereLoaderTest6')
                             ->has_relationship('sqlanywhere_loader_test4');
                     } 'cross-schema relationship in multi-db_schema';
 
                     lives_and {
-                        ok $test_schema->source('DbicslTest1SqlanywhereLoaderTest4')
+                        ok $test_schema->source('SqlanywhereLoaderTest4')
                             ->has_relationship('sqlanywhere_loader_test6s');
                     } 'cross-schema relationship in multi-db_schema';
 
                     lives_and {
-                        ok $test_schema->source('DbicslTest1SqlanywhereLoaderTest8')
+                        ok $test_schema->source('SqlanywhereLoaderTest8')
                             ->has_relationship('sqlanywhere_loader_test7');
                     } 'cross-schema relationship in multi-db_schema';
 
                     lives_and {
-                        ok $test_schema->source('DbicslTest2SqlanywhereLoaderTest7')
+                        ok $test_schema->source('SqlanywhereLoaderTest7')
                             ->has_relationship('sqlanywhere_loader_test8s');
                     } 'cross-schema relationship in multi-db_schema';
                 }
@@ -367,12 +406,7 @@ EOF
     },
 );
 
-if (not ($dbd_sqlanywhere_dsn || $odbc_dsn)) {
-    $tester->skip_tests('You need to set the DBICTEST_SQLANYWHERE_DSN, _USER and _PASS and/or the DBICTEST_SQLANYWHERE_ODBC_DSN, _USER and _PASS environment variables');
-}
-else {
-    $tester->run_tests();
-}
+$tester->run_tests();
 
 sub extra_cleanup {
     if (not $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) {