1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Add TAP tests for client programs

Reviewed-by: Pavel Stěhule <pavel.stehule@gmail.com>
Reviewed-by: Erik Rijkers <er@xs4all.nl>
This commit is contained in:
Peter Eisentraut
2014-04-14 21:33:46 -04:00
parent 7b5a9d61a8
commit 7d0f493f19
39 changed files with 745 additions and 3 deletions

View File

@ -14,3 +14,5 @@
/kwlookup.c
/mbprint.c
/print.c
/tmp_check/

View File

@ -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)

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');