Skip to content

Commit c2d15da

Browse files
committed
Add tests for "serial" and "smallserial" columns
The code was already there, but not covered by tests
1 parent f069af5 commit c2d15da

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

t/02_sequence.t

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use 5.006;
66
use strict;
77
use warnings;
88
use Data::Dumper;
9-
use Test::More tests => 12;
9+
use Test::More tests => 14;
1010
use lib 't','.';
1111
use CP_Testing;
1212

@@ -43,9 +43,11 @@ if ($ver < 80100) {
4343

4444

4545
my $seqname = 'cp_test_sequence';
46+
my $testtbl = 'sequence_test';
4647
$cp->drop_sequence_if_exists($seqname);
4748
$cp->drop_sequence_if_exists("${seqname}2");
4849
$cp->drop_sequence_if_exists("${seqname}'\"evil");
50+
$cp->drop_table_if_exists("$testtbl");
4951

5052
$t=qq{$S works when no sequences exist};
5153
like ($cp->run(''), qr{OK:.+No sequences found}, $t);
@@ -96,4 +98,28 @@ $dbh->commit();
9698
$t=qq{$S handles SQL quoting};
9799
like ($cp->run(''), qr{OK:.+'public."${seqname}''""evil"'}, $t); # extra " and ' because name is both identifier+literal quoted
98100

101+
$dbh->do("DROP SEQUENCE ${seqname}");
102+
$dbh->do("DROP SEQUENCE ${seqname}2");
103+
$dbh->do(qq{DROP SEQUENCE "${seqname}'""evil"});
104+
105+
# test integer column where the datatype range is smaller than the serial range
106+
$dbh->do("CREATE TABLE $testtbl (id serial)");
107+
$dbh->do("SELECT setval('${testtbl}_id_seq',2000000000)");
108+
$dbh->commit;
109+
$t=qq{$S handles "serial" column};
110+
like ($cp->run(''), qr{WARNING:.+public.sequence_test_id_seq=93% \(calls left=147483647\)}, $t);
111+
112+
if ($ver >= 90200) {
113+
# test smallint column where the datatype range is even smaller (and while we are at it, test --exclude)
114+
$dbh->do("ALTER TABLE $testtbl ADD COLUMN smallid smallserial");
115+
$dbh->do("SELECT setval('${testtbl}_smallid_seq',30000)");
116+
$dbh->commit;
117+
$t=qq{$S handles "smallserial" column};
118+
like ($cp->run('--exclude=sequence_test_id_seq'), qr{WARNING:.+public.sequence_test_smallid_seq=92% \(calls left=2767\)}, $t);
119+
} else {
120+
SKIP: {
121+
skip '"smallserial" needs PostgreSQL 9.2 or later', 2;
122+
}
123+
}
124+
99125
exit;

0 commit comments

Comments
 (0)