|
From: Chris W. <la...@us...> - 2001-11-04 17:42:53
|
Update of /cvsroot/openinteract/SPOPS/t
In directory usw-pr-cvs1:/tmp/cvs-serv3886
Modified Files:
30_dbi.t
Log Message:
modified to use the new DBI-specific configuration routines
Index: 30_dbi.t
===================================================================
RCS file: /cvsroot/openinteract/SPOPS/t/30_dbi.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** 30_dbi.t 2001/08/20 21:06:12 1.2
--- 30_dbi.t 2001/11/04 17:42:50 1.3
***************
*** 13,64 ****
use constant TEST_TABLE_NAME => 'spops_test';
- my %DRIVERS = (
- Pg => 'SPOPS::DBI::Pg',
- Sybase => 'SPOPS::DBI::Sybase',
- ASAny => 'SPOPS::DBI::Sybase',
- mysql => 'SPOPS::DBI::MySQL',
- );
-
{
- # Read in the config file and make sure we're supposed to run
! do "t/config.pl";
! my $config = _read_config_file();
! $config->{DBI_test} ||= 'n';
! if ( $config->{DBI_test} ne 'y' ) {
! print "1..0\n";
! print "Skipping test on this platform\n";
! exit;
! }
require Test::More;
Test::More->import( tests => NUM_TESTS );
my $driver_name = $config->{DBI_driver};
-
- # If DBD::ASAny, ensure it's the right version
-
- if ( $driver_name eq 'ASAny' ) {
- eval { require DBD::ASAny };
- if ( $@ ) {
- die "Cannot require DBD::ASAny module. Do you have it installed? (Error: $@)\n";
- }
-
- # get around annoying (!) -w declaration that var is only used once...
- my $dumb_ver = $DBD::ASAny::VERSION;
-
- # See that the right version is installed. 1.09 has been tested
- # and found ok. (Assuming higher versions will also be ok.)
! if ( $DBD::ASAny::VERSION < 1.09 ) {
! die <<ASANY;
! -- The DBD::ASAny driver prior version 1.09 did not support the {TYPE}
! attribute Please upgrade the driver before using SPOPS. If you do not
! do so, SPOPS will not work properly!
!
! Skipping text on this platform
! ASANY
! }
! }
# Ensure we can get to SPOPS::Initialize
--- 13,30 ----
use constant TEST_TABLE_NAME => 'spops_test';
{
! # Grab our DBI routines and be sure we're supposed to run.
+ do "t/dbi_config.pl";
+
+ my $config = test_dbi_run();
+
require Test::More;
Test::More->import( tests => NUM_TESTS );
my $driver_name = $config->{DBI_driver};
! my $spops_dbi_driver = check_dbd_compliance( $config, $driver_name );
# Ensure we can get to SPOPS::Initialize
***************
*** 72,76 ****
tester => {
class => 'DBITest',
! isa => [ $DRIVERS{ $config->{DBI_driver} }, 'SPOPS::DBI' ],
field => [ qw/ spops_id spops_name spops_goop spops_num / ],
id_field => 'spops_id',
--- 38,42 ----
tester => {
class => 'DBITest',
! isa => [ $spops_dbi_driver, 'SPOPS::DBI' ],
field => [ qw/ spops_id spops_name spops_goop spops_num / ],
id_field => 'spops_id',
***************
*** 85,145 ****
ok( $class_init_list->[0] eq 'DBITest', 'Initialize class' );
-
- # If the driver is *known* not to process {TYPE} info, we tell the
- # test class to include the type info in its configuration
-
- my %no_TYPE_dbd_drivers = ();
- if ( $no_TYPE_dbd_drivers{ $driver_name } ) {
- warn "\nDBD Driver $driver_name does not support {TYPE} information\n",
- "Installing manual types for test.\n";
- _assign_types();
- }
-
- my %dbd_driver_actions = ( Sybase => \&_sybase_setup );
- if ( ref $dbd_driver_actions{ $driver_name } eq 'CODE' ) {
- $dbd_driver_actions{ $driver_name }->( $config );
- }
-
- # First connect to the database
-
- my $db = DBI->connect( $config->{DBI_dsn},
- $config->{DBI_user},
- $config->{DBI_password} );
- unless ( $db ) {
- die "Cannot connect to database using parameters given. Please\n",
- "edit 'spops_test.conf' with correct information if you'd like\n",
- "to perform the tests. (Error: ", DBI->errstr, ")\n";
- }
! $db->{AutoCommit} = 1;
! $db->{ChopBlanks} = 1;
! $db->{RaiseError} = 1;
! $db->{PrintError} = 0;
!
! # This is standard, plain vanilla SQL; I don't want to have to do a
! # vendor-specific testing suite (argh!) -- although we could just
! # create sql files and read them in. Adapting the
! # OpenInteract::SQLInstall for strict SPOPS use might be
! # interesting...
!
! my $table_sql = <<SQL;
! CREATE TABLE @{[ TEST_TABLE_NAME ]} (
! spops_id int not null primary key,
! spops_name char(20) null,
! spops_goop char(20) not null,
! spops_num int default 2
! )
! SQL
! {
! my ( $sth );
! eval {
! $sth = $db->prepare( $table_sql );
! $sth->execute;
! };
! if ( $@ ) {
! die "Halting DBI tests -- Cannot create table in DBI database! Error: $@\n";
! }
! }
# Create an object
--- 51,59 ----
ok( $class_init_list->[0] eq 'DBITest', 'Initialize class' );
! # Create a database handle and create our testing table
! my $db = get_db_handle( $config );
! create_table( $db, 'simple', TEST_TABLE_NAME );
# Create an object
***************
*** 236,240 ****
}
! cleanup( $db );
# Future testing ideas:
--- 150,154 ----
}
! cleanup( $db, TEST_TABLE_NAME );
# Future testing ideas:
***************
*** 246,271 ****
}
-
- sub cleanup {
- my ( $db ) = @_;
- my $clean_sql = 'DROP TABLE ' . TEST_TABLE_NAME;
- eval { $db->do( $clean_sql ) };
- if ( $@ ) {
- warn "All tests passed ok, but we cannot remove the table (", TEST_TABLE_NAME, "). Error: $@\n";
- }
- $db->disconnect;
- }
-
-
- sub _sybase_setup {
- my $config = shift;
- $ENV{SYBASE} = $config->{ENV_SYBASE} if ( $config->{ENV_SYBASE} );
- }
-
-
- sub _assign_types {
- DBITest->CONFIG->{dbi_type_info} = { spops_id => 'num',
- spops_name => 'char',
- spops_goop => 'char',
- spops_num => 'num' };
- }
--- 160,161 ----
|