summaryrefslogtreecommitdiff
path: root/src/bin/scripts
diff options
context:
space:
mode:
authorPeter Eisentraut2014-04-15 01:33:46 +0000
committerPeter Eisentraut2014-04-15 01:33:46 +0000
commit7d0f493f19607774fdccb1a1ea06fdd96a3d9698 (patch)
tree71076e4ce36fa06d4637858f1435ef3f7ecd73b6 /src/bin/scripts
parent7b5a9d61a8202c46f4cc02878eafa8367080c59a (diff)
Add TAP tests for client programs
Reviewed-by: Pavel Stěhule <pavel.stehule@gmail.com> Reviewed-by: Erik Rijkers <er@xs4all.nl>
Diffstat (limited to 'src/bin/scripts')
-rw-r--r--src/bin/scripts/.gitignore2
-rw-r--r--src/bin/scripts/Makefile7
-rw-r--r--src/bin/scripts/t/010_clusterdb.pl18
-rw-r--r--src/bin/scripts/t/011_clusterdb_all.pl9
-rw-r--r--src/bin/scripts/t/020_createdb.pl16
-rw-r--r--src/bin/scripts/t/030_createlang.pl18
-rw-r--r--src/bin/scripts/t/040_createuser.pl26
-rw-r--r--src/bin/scripts/t/050_dropdb.pl16
-rw-r--r--src/bin/scripts/t/060_droplang.pl15
-rw-r--r--src/bin/scripts/t/070_dropuser.pl16
-rw-r--r--src/bin/scripts/t/080_pg_isready.pl15
-rw-r--r--src/bin/scripts/t/090_reindexdb.pl21
-rw-r--r--src/bin/scripts/t/091_reindexdb_all.pl11
-rw-r--r--src/bin/scripts/t/100_vacuumdb.pl17
-rw-r--r--src/bin/scripts/t/101_vacuumdb_all.pl9
15 files changed, 216 insertions, 0 deletions
diff --git a/src/bin/scripts/.gitignore b/src/bin/scripts/.gitignore
index 0b9b786da03..1056b2870c0 100644
--- a/src/bin/scripts/.gitignore
+++ b/src/bin/scripts/.gitignore
@@ -14,3 +14,5 @@
/kwlookup.c
/mbprint.c
/print.c
+
+/tmp_check/
diff --git a/src/bin/scripts/Makefile b/src/bin/scripts/Makefile
index b5d9207b293..de0e11f7142 100644
--- a/src/bin/scripts/Makefile
+++ b/src/bin/scripts/Makefile
@@ -68,3 +68,10 @@ clean distclean maintainer-clean:
rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS))
rm -f common.o dumputils.o kwlookup.o keywords.o print.o mbprint.o $(WIN32RES)
rm -f dumputils.c print.c mbprint.c kwlookup.c keywords.c
+
+
+check: all
+ $(prove_check)
+
+installcheck:
+ $(prove_installcheck)
diff --git a/src/bin/scripts/t/010_clusterdb.pl b/src/bin/scripts/t/010_clusterdb.pl
new file mode 100644
index 00000000000..371b2dd2d3d
--- /dev/null
+++ b/src/bin/scripts/t/010_clusterdb.pl
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 6;
+
+program_help_ok('clusterdb');
+program_version_ok('clusterdb');
+program_options_handling_ok('clusterdb');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+issues_sql_like(['clusterdb', 'postgres'], qr/statement: CLUSTER;/, 'SQL CLUSTER run');
+
+command_fails(['clusterdb', '-t', 'nonexistent', 'postgres'], 'fails with nonexistent table');
+
+psql 'postgres', 'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x';
+issues_sql_like(['clusterdb', 'postgres', '-t', 'test1'], qr/statement: CLUSTER test1;/, 'cluster specific table');
diff --git a/src/bin/scripts/t/011_clusterdb_all.pl b/src/bin/scripts/t/011_clusterdb_all.pl
new file mode 100644
index 00000000000..304c4befa55
--- /dev/null
+++ b/src/bin/scripts/t/011_clusterdb_all.pl
@@ -0,0 +1,9 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 1;
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+issues_sql_like(['clusterdb', '-a'], qr/statement: CLUSTER.*statement: CLUSTER/s, 'cluster all databases');
diff --git a/src/bin/scripts/t/020_createdb.pl b/src/bin/scripts/t/020_createdb.pl
new file mode 100644
index 00000000000..8b82a2bd96c
--- /dev/null
+++ b/src/bin/scripts/t/020_createdb.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 6;
+
+program_help_ok('createdb');
+program_version_ok('createdb');
+program_options_handling_ok('createdb');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+issues_sql_like(['createdb', 'foobar1'], qr/statement: CREATE DATABASE foobar1/, 'SQL CREATE DATABASE run');
+issues_sql_like(['createdb', 'foobar2', '-l', 'C', '-E', 'LATIN1', '-T', 'template0'], qr/statement: CREATE DATABASE foobar2 ENCODING 'LATIN1'/, 'create database with encoding');
+
+command_fails(['createdb', 'foobar1'], 'fails if database already exists');
diff --git a/src/bin/scripts/t/030_createlang.pl b/src/bin/scripts/t/030_createlang.pl
new file mode 100644
index 00000000000..9a87f4c89c6
--- /dev/null
+++ b/src/bin/scripts/t/030_createlang.pl
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 6;
+
+program_help_ok('createlang');
+program_version_ok('createlang');
+program_options_handling_ok('createlang');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+command_fails(['createlang', 'plpgsql', 'postgres'], 'fails if language already exists');
+
+psql 'postgres', 'DROP EXTENSION plpgsql';
+issues_sql_like(['createlang', 'plpgsql', 'postgres'], qr/statement: CREATE EXTENSION "plpgsql"/, 'SQL CREATE EXTENSION run');
+
+command_like(['createlang', '--list', 'postgres'], qr/plpgsql/, 'list output');
diff --git a/src/bin/scripts/t/040_createuser.pl b/src/bin/scripts/t/040_createuser.pl
new file mode 100644
index 00000000000..922873ab374
--- /dev/null
+++ b/src/bin/scripts/t/040_createuser.pl
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 8;
+
+program_help_ok('createuser');
+program_version_ok('createuser');
+program_options_handling_ok('createuser');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+issues_sql_like(['createuser', 'user1'],
+ qr/statement: CREATE ROLE user1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;/,
+ 'SQL CREATE USER run');
+issues_sql_like(['createuser', '-L', 'role1'],
+ qr/statement: CREATE ROLE role1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN;/,
+ 'create a non-login role');
+issues_sql_like(['createuser', '-r', 'user2'],
+ qr/statement: CREATE ROLE user2 NOSUPERUSER NOCREATEDB CREATEROLE INHERIT LOGIN;/,
+ 'create a CREATEROLE user');
+issues_sql_like(['createuser', '-s', 'user3'],
+ qr/statement: CREATE ROLE user3 SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;/,
+ 'create a superuser');
+
+command_fails(['createuser', 'user1'], 'fails if role already exists');
diff --git a/src/bin/scripts/t/050_dropdb.pl b/src/bin/scripts/t/050_dropdb.pl
new file mode 100644
index 00000000000..3662dd01c1d
--- /dev/null
+++ b/src/bin/scripts/t/050_dropdb.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 5;
+
+program_help_ok('dropdb');
+program_version_ok('dropdb');
+program_options_handling_ok('dropdb');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+psql 'postgres', 'CREATE DATABASE foobar1';
+issues_sql_like(['dropdb', 'foobar1'], qr/statement: DROP DATABASE foobar1/, 'SQL DROP DATABASE run');
+
+command_fails(['dropdb', 'nonexistent'], 'fails with nonexistent database');
diff --git a/src/bin/scripts/t/060_droplang.pl b/src/bin/scripts/t/060_droplang.pl
new file mode 100644
index 00000000000..47cb48f1171
--- /dev/null
+++ b/src/bin/scripts/t/060_droplang.pl
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 5;
+
+program_help_ok('droplang');
+program_version_ok('droplang');
+program_options_handling_ok('droplang');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+issues_sql_like(['droplang', 'plpgsql', 'postgres'], qr/statement: DROP EXTENSION "plpgsql"/, 'SQL DROP EXTENSION run');
+
+command_fails(['droplang', 'nonexistent', 'postgres'], 'fails with nonexistent language');
diff --git a/src/bin/scripts/t/070_dropuser.pl b/src/bin/scripts/t/070_dropuser.pl
new file mode 100644
index 00000000000..495636ae846
--- /dev/null
+++ b/src/bin/scripts/t/070_dropuser.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 5;
+
+program_help_ok('dropuser');
+program_version_ok('dropuser');
+program_options_handling_ok('dropuser');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+psql 'postgres', 'CREATE ROLE foobar1';
+issues_sql_like(['dropuser', 'foobar1'], qr/statement: DROP ROLE foobar1/, 'SQL DROP ROLE run');
+
+command_fails(['dropuser', 'nonexistent'], 'fails with nonexistent user');
diff --git a/src/bin/scripts/t/080_pg_isready.pl b/src/bin/scripts/t/080_pg_isready.pl
new file mode 100644
index 00000000000..03c3657153f
--- /dev/null
+++ b/src/bin/scripts/t/080_pg_isready.pl
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 5;
+
+program_help_ok('pg_isready');
+program_version_ok('pg_isready');
+program_options_handling_ok('pg_isready');
+
+command_fails(['pg_isready'], 'fails with no server running');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+command_ok(['pg_isready'], 'succeeds with server running');
diff --git a/src/bin/scripts/t/090_reindexdb.pl b/src/bin/scripts/t/090_reindexdb.pl
new file mode 100644
index 00000000000..18756e86aac
--- /dev/null
+++ b/src/bin/scripts/t/090_reindexdb.pl
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 7;
+
+program_help_ok('reindexdb');
+program_version_ok('reindexdb');
+program_options_handling_ok('reindexdb');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+$ENV{PGOPTIONS} = '--client-min-messages=WARNING';
+
+issues_sql_like(['reindexdb', 'postgres'], qr/statement: REINDEX DATABASE postgres;/, 'SQL REINDEX run');
+
+psql 'postgres', 'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a);';
+issues_sql_like(['reindexdb', 'postgres', '-t', 'test1'], qr/statement: REINDEX TABLE test1;/, 'reindex specific table');
+issues_sql_like(['reindexdb', 'postgres', '-i', 'test1x'], qr/statement: REINDEX INDEX test1x;/, 'reindex specific index');
+
+issues_sql_like(['reindexdb', 'postgres', '-s'], qr/statement: REINDEX SYSTEM postgres;/, 'reindex system tables');
diff --git a/src/bin/scripts/t/091_reindexdb_all.pl b/src/bin/scripts/t/091_reindexdb_all.pl
new file mode 100644
index 00000000000..eee8ba8ed9c
--- /dev/null
+++ b/src/bin/scripts/t/091_reindexdb_all.pl
@@ -0,0 +1,11 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 1;
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+$ENV{PGOPTIONS} = '--client-min-messages=WARNING';
+
+issues_sql_like(['reindexdb', '-a'], qr/statement: REINDEX.*statement: REINDEX/s, 'reindex all databases');
diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl
new file mode 100644
index 00000000000..39f1cec8a14
--- /dev/null
+++ b/src/bin/scripts/t/100_vacuumdb.pl
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 8;
+
+program_help_ok('vacuumdb');
+program_version_ok('vacuumdb');
+program_options_handling_ok('vacuumdb');
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+issues_sql_like(['vacuumdb', 'postgres'], qr/statement: VACUUM;/, 'SQL VACUUM run');
+issues_sql_like(['vacuumdb', '-f', 'postgres'], qr/statement: VACUUM \(FULL\);/, 'vacuumdb -f');
+issues_sql_like(['vacuumdb', '-F', 'postgres'], qr/statement: VACUUM \(FREEZE\);/, 'vacuumdb -F');
+issues_sql_like(['vacuumdb', '-z', 'postgres'], qr/statement: VACUUM \(ANALYZE\);/, 'vacuumdb -z');
+issues_sql_like(['vacuumdb', '-Z', 'postgres'], qr/statement: ANALYZE;/, 'vacuumdb -z');
diff --git a/src/bin/scripts/t/101_vacuumdb_all.pl b/src/bin/scripts/t/101_vacuumdb_all.pl
new file mode 100644
index 00000000000..b5779bcf12c
--- /dev/null
+++ b/src/bin/scripts/t/101_vacuumdb_all.pl
@@ -0,0 +1,9 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 1;
+
+my $tempdir = tempdir;
+start_test_server $tempdir;
+
+issues_sql_like(['vacuumdb', '-a'], qr/statement: VACUUM.*statement: VACUUM/s, 'vacuum all databases');