From: Robert Buels Date: Wed, 2 Sep 2009 18:48:12 +0000 (+0000) Subject: more cleanup of pg tests, added cascade to drop function, cleaned up create and drop... X-Git-Tag: v0.08111~14^2~31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2fbf50ff3db12c7ea5612a8785fc3504d48dcb2c;p=dbsrgits%2FDBIx-Class.git more cleanup of pg tests, added cascade to drop function, cleaned up create and drop of schemas to use dbh_do --- diff --git a/t/72pg.t b/t/72pg.t index 4b94d9b..f839937 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -53,8 +53,8 @@ DBICTest::Schema->load_classes( map {s/.+:://;$_} @test_classes ) if @test_class my $schema = DBICTest::Schema->connect($dsn, $user, $pass); my $dbh = $schema->storage->dbh; -drop_test_schema($dbh, 'no warn'); -create_test_schema($dbh); +drop_test_schema($schema, 'no warn'); +create_test_schema($schema); ### begin main tests @@ -368,22 +368,22 @@ for (1..5) { my $st = $schema->resultset('SequenceTest')->create({ name => 'foo', pkid1 => 55 }); is($st->pkid1, 55, "Oracle Auto-PK without trigger: First primary key set manually"); -sub _cleanup { - my $schema = shift or return; - local $SIG{__WARN__} = sub {}; +done_testing; exit; -END { drop_test_schema($dbh) } +END { drop_test_schema($schema) } ######### SUBROUTINES sub create_test_schema { - my $dbh = shift; + my $schema = shift; + $schema->storage->dbh_do(sub { + my (undef,$dbh) = @_; - local $SIG{__WARN__} = sub {}; + local $dbh->{Warn} = 0; - my $std_artist_table = <do("CREATE SCHEMA testschema"); - $dbh->do("CREATE TABLE testschema.artist $std_artist_table"); - $dbh->do(<do("CREATE SCHEMA testschema"); + $dbh->do("CREATE TABLE testschema.artist $std_artist_table"); + $dbh->do(<do("CREATE SEQUENCE pkid1_seq START 1 MAXVALUE 999999 MINVALUE 0"); - $dbh->do("CREATE SEQUENCE pkid2_seq START 10 MAXVALUE 999999 MINVALUE 0"); - $dbh->do("CREATE SEQUENCE nonpkid_seq START 20 MAXVALUE 999999 MINVALUE 0"); - $dbh->do(<do("CREATE SEQUENCE pkid1_seq START 1 MAXVALUE 999999 MINVALUE 0"); + $dbh->do("CREATE SEQUENCE pkid2_seq START 10 MAXVALUE 999999 MINVALUE 0"); + $dbh->do("CREATE SEQUENCE nonpkid_seq START 20 MAXVALUE 999999 MINVALUE 0"); + $dbh->do(<do(<do(<do("CREATE SCHEMA anothertestschema"); - $dbh->do("CREATE TABLE anothertestschema.artist $std_artist_table"); - $dbh->do("CREATE SCHEMA yetanothertestschema"); - $dbh->do("CREATE TABLE yetanothertestschema.artist $std_artist_table"); - $dbh->do('set search_path=testschema,public'); - $dbh->do("CREATE SCHEMA unq_nextval_schema"); - $dbh->do("CREATE SCHEMA unq_nextval_schema2"); - $dbh->do(<do("CREATE SCHEMA anothertestschema"); + $dbh->do("CREATE TABLE anothertestschema.artist $std_artist_table"); + $dbh->do("CREATE SCHEMA yetanothertestschema"); + $dbh->do("CREATE TABLE yetanothertestschema.artist $std_artist_table"); + $dbh->do('set search_path=testschema,public'); + $dbh->do("CREATE SCHEMA unq_nextval_schema"); + $dbh->do("CREATE SCHEMA unq_nextval_schema2"); + $dbh->do(<do('set search_path=public,testschema,yetanothertestschema'); - $dbh->do('create sequence public.artist_artistid_seq'); #< in the public schema - $dbh->do(<do('set search_path=public,testschema,yetanothertestschema'); + $dbh->do('create sequence public.artist_artistid_seq'); #< in the public schema + $dbh->do(<do('set search_path=testschema,public'); + $dbh->do('set search_path=testschema,public'); + }); } sub drop_test_schema { - my ( $dbh, $no_warn ) = @_; - - return unless $dbh->ping; - - for my $stat ( - 'DROP SCHEMA testschema CASCADE', - 'DROP SCHEMA anothertestschema CASCADE', - 'DROP SCHEMA yetanothertestschema CASCADE', - 'DROP SEQUENCE pkid1_seq', - 'DROP SEQUENCE pkid2_seq', - 'DROP SEQUENCE nonpkid_seq', - ) { - eval { $schema->storage->_do_query ($stat) }; - diag $@ if $@ && !$no_warn; - } + my ( $schema, $no_warn ) = @_; + + $schema->storage->dbh_do(sub { + my (undef,$dbh) = @_; + + local $dbh->{Warn} = 0; + + for my $stat ( + 'DROP SCHEMA unq_nextval_schema2 CASCADE', + 'DROP SEQUENCE public.artist_artistid_seq', + 'DROP SCHEMA unq_nextval_schema CASCADE', + 'DROP SCHEMA testschema CASCADE', + 'DROP SEQUENCE pkid1_seq', + 'DROP SEQUENCE pkid2_seq', + 'DROP SEQUENCE nonpkid_seq', + 'DROP SCHEMA anothertestschema CASCADE', + 'DROP SCHEMA yetanothertestschema CASCADE', + ) { + eval { $dbh->do ($stat) }; + diag $@ if $@ && !$no_warn; + } + }); } done_testing; - -END { _cleanup($schema) }