From: Chris Hilton Date: Mon, 27 Jun 2005 22:07:39 +0000 (+0000) Subject: Added additional tests for sqlt-diff X-Git-Tag: v0.11008~520 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fb3e4caf2e5d776c8243ba48470c2688b3f25326;p=dbsrgits%2FSQL-Translator.git Added additional tests for sqlt-diff --- diff --git a/t/30sqlt-diff.t b/t/30sqlt-diff.t index c745dae..95cc3ac 100644 --- a/t/30sqlt-diff.t +++ b/t/30sqlt-diff.t @@ -25,8 +25,9 @@ my $create2 = (-d "t") : catfile($Bin, "t", @create2); BEGIN { - maybe_plan(3, + maybe_plan(12, 'SQL::Translator::Parser::SQLite', + 'SQL::Translator::Parser::MySQL', 'SQL::Translator::Producer::YAML', ); } @@ -39,3 +40,38 @@ my $out = `@cmd`; like($out, qr/ALTER TABLE person CHANGE iq/, "Detected altered 'iq' field"); like($out, qr/ALTER TABLE person ADD is_rock_star/, "Detected missing rock star field"); + +@cmd = ($sqlt_diff, "$create1=SQLite", "$create1=SQLite"); +$out = `@cmd`; + +like($out, qr/There were no differences/, "Properly detected no differences"); + +my @mysql_create1 = qw(data mysql create.sql); +my @mysql_create2 = qw(data mysql create2.sql); + +my $mysql_create1 = (-d "t") + ? catfile($Bin, @mysql_create1) + : catfile($Bin, "t", @mysql_create1); + +my $mysql_create2 = (-d "t") + ? catfile($Bin, @mysql_create2) + : catfile($Bin, "t", @mysql_create2); + +@cmd = ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create2=MySQL"); +$out = `@cmd`; + +like($out, qr/ALTER TABLE person CHANGE person_id/, "Detected altered 'person_id' field"); +like($out, qr/ALTER TABLE person CHANGE iq/, "Detected altered 'iq' field"); +like($out, qr/ALTER TABLE person CHANGE name/, "Detected altered 'name' field"); +like($out, qr/ALTER TABLE person CHANGE age/, "Detected altered 'age' field"); +like($out, qr/ALTER TABLE person ADD is_rock_star/, + "Detected missing rock star field"); +like($out, qr/ALTER TABLE person ADD UNIQUE UC_person_id/, + "Detected missing unique constraint"); +like($out, qr/ALTER TABLE person ENGINE=InnoDB;/, + "Detected altered table option"); + +@cmd = ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create1=MySQL"); +$out = `@cmd`; + +like($out, qr/There were no differences/, "Properly detected no differences"); diff --git a/t/data/mysql/create.sql b/t/data/mysql/create.sql new file mode 100644 index 0000000..51dbcc7 --- /dev/null +++ b/t/data/mysql/create.sql @@ -0,0 +1,10 @@ +create table person ( + person_id INTEGER PRIMARY KEY, + name varchar(20), + age integer, + weight double(11,2), + iq tinyint default '0', + description text +) ENGINE=MyISAM; + +create unique index u_name on person (name); diff --git a/t/data/mysql/create2.sql b/t/data/mysql/create2.sql new file mode 100644 index 0000000..8a9e768 --- /dev/null +++ b/t/data/mysql/create2.sql @@ -0,0 +1,12 @@ +create table person ( + person_id INTEGER PRIMARY KEY AUTO_INCREMENT, + name varchar(20) not null, + age integer default '18', + weight double(11,2), + iq int default '0', + is_rock_star tinyint default '1', + description text, + UNIQUE KEY UC_person_id (person_id) +) ENGINE=InnoDB; + +create unique index u_name on person (name);