summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Berg2015-03-23 15:38:18 +0000
committerChristoph Berg2015-03-23 15:44:37 +0000
commitc2d15dafc62c3a7498a10cf28f4e6c0fc1340987 (patch)
tree0510bb89a099c38726680a54b0fe895943d0d39f
parentf069af5d60587c93efd7c190706f08b81d6fad1f (diff)
Add tests for "serial" and "smallserial" columns
The code was already there, but not covered by tests
-rw-r--r--t/02_sequence.t28
1 files changed, 27 insertions, 1 deletions
diff --git a/t/02_sequence.t b/t/02_sequence.t
index b1fa3ea31..efce3a02c 100644
--- a/t/02_sequence.t
+++ b/t/02_sequence.t
@@ -6,7 +6,7 @@ use 5.006;
use strict;
use warnings;
use Data::Dumper;
-use Test::More tests => 12;
+use Test::More tests => 14;
use lib 't','.';
use CP_Testing;
@@ -43,9 +43,11 @@ if ($ver < 80100) {
my $seqname = 'cp_test_sequence';
+my $testtbl = 'sequence_test';
$cp->drop_sequence_if_exists($seqname);
$cp->drop_sequence_if_exists("${seqname}2");
$cp->drop_sequence_if_exists("${seqname}'\"evil");
+$cp->drop_table_if_exists("$testtbl");
$t=qq{$S works when no sequences exist};
like ($cp->run(''), qr{OK:.+No sequences found}, $t);
@@ -96,4 +98,28 @@ $dbh->commit();
$t=qq{$S handles SQL quoting};
like ($cp->run(''), qr{OK:.+'public."${seqname}''""evil"'}, $t); # extra " and ' because name is both identifier+literal quoted
+$dbh->do("DROP SEQUENCE ${seqname}");
+$dbh->do("DROP SEQUENCE ${seqname}2");
+$dbh->do(qq{DROP SEQUENCE "${seqname}'""evil"});
+
+# test integer column where the datatype range is smaller than the serial range
+$dbh->do("CREATE TABLE $testtbl (id serial)");
+$dbh->do("SELECT setval('${testtbl}_id_seq',2000000000)");
+$dbh->commit;
+$t=qq{$S handles "serial" column};
+like ($cp->run(''), qr{WARNING:.+public.sequence_test_id_seq=93% \(calls left=147483647\)}, $t);
+
+if ($ver >= 90200) {
+ # test smallint column where the datatype range is even smaller (and while we are at it, test --exclude)
+ $dbh->do("ALTER TABLE $testtbl ADD COLUMN smallid smallserial");
+ $dbh->do("SELECT setval('${testtbl}_smallid_seq',30000)");
+ $dbh->commit;
+ $t=qq{$S handles "smallserial" column};
+ like ($cp->run('--exclude=sequence_test_id_seq'), qr{WARNING:.+public.sequence_test_smallid_seq=92% \(calls left=2767\)}, $t);
+} else {
+ SKIP: {
+ skip '"smallserial" needs PostgreSQL 9.2 or later', 2;
+ }
+}
+
exit;