DBIx-Compare

 view release on metacpan or  search on metacpan

t/DBIx_Compare.t  view on Meta::CPAN

#! /usr/bin/perl -w

use strict;

use Test::More tests=>35;
use Test::Group;
use Test::Differences;

use DBI;

# 1
BEGIN {
	use_ok('DBIx::Compare');
}

my $user_name = 'test';
my $user_pass = '';
my $dsn1 = "DBI:mysql:test:localhost";
my $dsn2 = "DBI:mysql:test2:localhost";
my ($to_test,$dbh1,$dbh2,$oDB_Content);

eval {
	require DBD::mysql;
};
if ($@){
	diag("Skipping 19 tests: Could not create the test databases because the driver 'DBD::mysql' is not installed");
} else {
	$dbh1 = DBI->connect($dsn1, $user_name, $user_pass);
	$dbh2 = DBI->connect($dsn2, $user_name, $user_pass);
	if ($dbh1 && $dbh2 && create_test_db($dbh1) && create_test_db($dbh2)){
		$to_test = 1;
	} else {
		# because Test::Harness doesn't seem to want to output my skips!
		diag("Skipping 19 tests: Could not create the test databases");
	}
}

SKIP: {
	skip("Could not create the test databases", 19) unless ($to_test);
	
	#2
	test 'object init' => sub {
		ok($oDB_Content = db_comparison->new($dbh1,$dbh2),'init');
		isa_ok($oDB_Content,'mysql_comparison','DBIx::Compare::mysql object');
		isa_ok($oDB_Content,'db_comparison','DBIx::Compare object');
	};

	#3
	test 'dbh stuff' => sub {
		my ($dbh1b,$dbh2b) = $oDB_Content->get_dbh;
		isa_ok($dbh1b,'DBI::db','dbh1 after set');
		isa_ok($dbh2b,'DBI::db','dbh2 after set');
		ok(my @aNames = $oDB_Content->get_db_names,'get_db_names');
		eq_or_diff \@aNames,['test:localhost','test2:localhost'],'database names';
		cmp_ok($oDB_Content->get_db_driver,'eq','mysql','get_db_driver');
	};

	#4
	test 'table lists' => sub {
		ok(my @aTables = $oDB_Content->get_tables,'get_tables 1 & 2');
		eq_or_diff \@aTables,[['filter','fluorochrome','laser','procedure_info','protocol_type'],['filter','fluorochrome','laser','procedure_info','protocol_type']],'table lists';
		ok(my $aTable1 = $oDB_Content->get_tables,'get_tables 1');
		eq_or_diff $aTable1,$aTables[0],'tables vs tables1';
	};

	#5
	test 'primary keys' => sub {



( run in 0.471 second using v1.01-cache-2.11-cpan-6aa56a78535 )