X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=t%2Fdb_colinfo.t;fp=t%2Fdb_colinfo.t;h=ef2466fb002aa067a85aebf2fbed03dcd6008d77;hb=d3bd3060bf3f11775d9f40ee983f71949404f794;hp=cb1b4361e1f91c0b6629a6a517b2c7390097cba8;hpb=abb63001d28afe34e807dbd4449feaded558c528;p=maypole.git diff --git a/t/db_colinfo.t b/t/db_colinfo.t index cb1b436..ef2466f 100755 --- a/t/db_colinfo.t +++ b/t/db_colinfo.t @@ -2,7 +2,7 @@ use Test::More; use lib 'ex'; # Where BeerDB should live BEGIN { - plan tests => 26; + plan tests => 44; } $db = 'test'; @@ -12,7 +12,7 @@ $table = "beer_test"; $sql = " create table $table ( id integer auto_increment primary key, - name char(30), + name char(30) NOT NULL default 'noname', url varchar(120), score smallint(2), price decimal(3,2), @@ -22,7 +22,7 @@ create table $table ( tasted date NOT NULL, created timestamp default CURRENT_TIMESTAMP, modified datetime default NULL, - style mediumint(8) default 1, + style mediumint(8) NOT NULL default 1, brewery integer default NULL );"; @@ -39,10 +39,28 @@ create table $table ( score => 'smallint', price => 'decimal', abv => 'varchar', - notes => '(text|blob)', + notes => '(text|blob)', image => 'blob', ); +# correct defaults +%correct_defaults = ( + created => 'CURRENT_TIMESTAMP', + modified => undef, + style => 1, + name => 'noname', +); + +# correct nullables +%correct_nullables = ( + brewery => 1, + modified => 1, + style => 0, + name => 0, + tasted => 0, +); + + # Runs tests on column_* method of $class using %correct data hash # usage: run_method_tests ($class, $method, %correct); sub run_method_tests { @@ -86,7 +104,7 @@ if ($databases{test}) { $skip_msg = "Could not connect to MySQL using database 'test' as it doesn't exist, sorry"; } -$skip_howmany = 13; +$skip_howmany = 22; SKIP: { skip $skip_msg, $skip_howmany if $err; @@ -94,8 +112,8 @@ SKIP: { $DB_Class->db_Main->do($sql); $DB_Class->table($table); run_method_tests($DB_Class,'column_type', %correct_types); - #run_method_tests($DB_Class,'column_default', %correct_defaults); - #run_method_tests($DB_Class,'column_nullable', %correct_defaults); + run_method_tests($DB_Class,'column_default', %correct_defaults); + run_method_tests($DB_Class,'column_nullable', %correct_nullables); }; # SQLite test @@ -107,7 +125,6 @@ package main; $DB_Class = 'BeerDB::BeerTestsqlite'; $err = undef; -#unlink "t/test.db"; if ( !-e "t/test.db" ) { eval {make_sqlite_db($sql)}; $err = $@; @@ -121,20 +138,18 @@ unless ($err) { } $skip_msg = "Could not connect to SQLite database 't/test.db'"; -$skip_howmany = 13; +$skip_howmany = 22; SKIP: { skip $skip_msg, $skip_howmany if $err; $DB_Class->table($table); run_method_tests($DB_Class,'column_type', %correct_types); - #run_method_tests($DB_Class,'column_default', %correct_defaults); - #run_method_tests($DB_Class,'column_nullable', %correct_defaults); + run_method_tests($DB_Class,'column_default', %correct_defaults); + run_method_tests($DB_Class,'column_nullable', %correct_nullables); }; - - # Helper methods, TODO -- put these somewhere where tests can use them. # returns "best" available sqlite driver or dies