1use strict; 2use Test::More; 3 4BEGIN { 5 eval { require DBD::Pg; }; 6 plan skip_all => 'needs DBD::Pg for testing' if $@; 7} 8 9use lib 't/testlib'; 10use Binary; 11 12eval { Binary->CONSTRUCT; }; 13if ($@) { 14 diag <<SKIP; 15Pg connection failed ($@). Set env variables DBD_PG_DBNAME, DBD_PG_USER, 16DBD_PG_PASSWD to enable testing. 17SKIP 18 plan skip_all => 'Pg connection failed.'; 19} 20 21plan tests => 40; 22 23Binary->data_type(bin => DBI::SQL_BINARY); 24Binary->db_Main->{ AutoCommit } = 0; 25 26SKIP: { 27 for my $id (1 .. 10) { 28 my $bin = "foo\0$id"; 29 my $obj = eval { Binary->insert( 30 { 31 # id => $id, 32 bin => $bin, 33 } 34 ) }; 35 skip $@, 40 if $@; 36 isa_ok $obj, 'Binary'; 37 is $obj->id, $id, "id is $id"; 38 is $obj->bin, $bin, "insert: bin ok"; 39 40 $obj->bin("bar\0$id"); 41 $obj->update; 42 43 if ($obj->id % 2) { 44 $obj->dbi_commit; 45 my $new_obj = $obj->retrieve($obj->id); 46 is $obj->bin, "bar\0$id", "update: bin ok"; 47 } else { 48 $obj->dbi_rollback; 49 my $new_obj = $obj->retrieve($obj->id); 50 is $new_obj, undef, "Rolled back"; 51 } 52 } 53} 54 55