mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further reuse by creating a new Perl package PostgresNode, which is an object-oriented representation of a single server, with some support routines such as init, start, stop, psql. This serves as a better basis on which to build further test code, and enables writing tests that use more than one server without too much complication. This commit modifies a lot of the existing test files, mostly to remove explicit calls to system commands (pg_ctl) replacing them with method calls of a PostgresNode object. The result is quite a bit more straightforward. Also move some initialization code to BEGIN and INIT blocks instead of having it straight in as top-level code. This commit also introduces package RecursiveCopy so that we can copy whole directories without having to depend on packages that may not be present on vanilla Perl 5.8 installations. I also ran perltidy on the modified files, which changes some code sites that are not otherwise touched by this patch. I tried to avoid this, but it ended up being more trouble than it's worth. Authors: Michael Paquier, Álvaro Herrera Review: Noah Misch
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use PostgresNode;
|
||||
use TestLib;
|
||||
use Test::More tests => 17;
|
||||
|
||||
@ -7,24 +9,26 @@ program_help_ok('createuser');
|
||||
program_version_ok('createuser');
|
||||
program_options_handling_ok('createuser');
|
||||
|
||||
my $tempdir = tempdir;
|
||||
start_test_server $tempdir;
|
||||
my $node = get_new_node();
|
||||
$node->init;
|
||||
$node->start;
|
||||
|
||||
issues_sql_like(
|
||||
$node->issues_sql_like(
|
||||
[ 'createuser', 'user1' ],
|
||||
qr/statement: CREATE ROLE user1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;/,
|
||||
'SQL CREATE USER run');
|
||||
issues_sql_like(
|
||||
$node->issues_sql_like(
|
||||
[ 'createuser', '-L', 'role1' ],
|
||||
qr/statement: CREATE ROLE role1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN;/,
|
||||
'create a non-login role');
|
||||
issues_sql_like(
|
||||
$node->issues_sql_like(
|
||||
[ 'createuser', '-r', 'user2' ],
|
||||
qr/statement: CREATE ROLE user2 NOSUPERUSER NOCREATEDB CREATEROLE INHERIT LOGIN;/,
|
||||
'create a CREATEROLE user');
|
||||
issues_sql_like(
|
||||
$node->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');
|
||||
$node->command_fails([ 'createuser', 'user1' ],
|
||||
'fails if role already exists');
|
||||
|
Reference in New Issue
Block a user