mirror of
https://github.com/postgres/postgres.git
synced 2025-04-20 00:42:27 +03:00
This commit rewrites a good chunk of the command arrays in TAP tests with a grammar based on the following rules: - Fat commas are used between option names and their values, making it clear to both humans and perltidy that values and names are bound together. This is particularly useful for the readability of multi-line command arrays, and there are plenty of them in the TAP tests. Most of the test code is updated to use this style. Some commands used parenthesis to show the link, or attached values and options in a single string. These are updated to use fat commas instead. - Option names are switched to use their long names, making them more self-documented. Based on a suggestion by Andrew Dunstan. - Add some trailing commas after the last item in multi-line arrays, which is a common perl style. Not all the places are taken care of, but this covers a very good chunk of them. Author: Dagfinn Ilmari Mannsåker Reviewed-by: Michael Paquier, Peter Smith, Euler Taveira Discussion: https://postgr.es/m/87jzc46d8u.fsf@wibble.ilmari.org
94 lines
3.9 KiB
Perl
94 lines
3.9 KiB
Perl
|
|
# Copyright (c) 2021-2025, PostgreSQL Global Development Group
|
|
|
|
use strict;
|
|
use warnings FATAL => 'all';
|
|
|
|
use PostgreSQL::Test::Cluster;
|
|
use PostgreSQL::Test::Utils;
|
|
use Test::More;
|
|
|
|
program_help_ok('createuser');
|
|
program_version_ok('createuser');
|
|
program_options_handling_ok('createuser');
|
|
|
|
my $node = PostgreSQL::Test::Cluster->new('main');
|
|
$node->init;
|
|
$node->start;
|
|
|
|
$node->issues_sql_like(
|
|
[ 'createuser', 'regress_user1' ],
|
|
qr/statement: CREATE ROLE regress_user1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;/,
|
|
'SQL CREATE USER run');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--no-login', 'regress_role1' ],
|
|
qr/statement: CREATE ROLE regress_role1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN NOREPLICATION NOBYPASSRLS;/,
|
|
'create a non-login role');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--createrole', 'regress user2' ],
|
|
qr/statement: CREATE ROLE "regress user2" NOSUPERUSER NOCREATEDB CREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;/,
|
|
'create a CREATEROLE user');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--superuser', 'regress_user3' ],
|
|
qr/statement: CREATE ROLE regress_user3 SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;/,
|
|
'create a superuser');
|
|
$node->issues_sql_like(
|
|
[
|
|
'createuser',
|
|
'--with-admin' => 'regress_user1',
|
|
'--with-admin' => 'regress user2',
|
|
'regress user #4'
|
|
],
|
|
qr/statement: CREATE ROLE "regress user #4" NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS ADMIN regress_user1,"regress user2";/,
|
|
'add a role as a member with admin option of the newly created role');
|
|
$node->issues_sql_like(
|
|
[
|
|
'createuser',
|
|
'REGRESS_USER5',
|
|
'--with-member' => 'regress_user3',
|
|
'--with-member' => 'regress user #4'
|
|
],
|
|
qr/statement: CREATE ROLE "REGRESS_USER5" NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS ROLE regress_user3,"regress user #4";/,
|
|
'add a role as a member of the newly created role');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--valid-until' => '2029 12 31', 'regress_user6' ],
|
|
qr/statement: CREATE ROLE regress_user6 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS VALID UNTIL \'2029 12 31\';/,
|
|
'create a role with a password expiration date');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--bypassrls', 'regress_user7' ],
|
|
qr/statement: CREATE ROLE regress_user7 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION BYPASSRLS;/,
|
|
'create a BYPASSRLS role');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--no-bypassrls', 'regress_user8' ],
|
|
qr/statement: CREATE ROLE regress_user8 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;/,
|
|
'create a role without BYPASSRLS');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--with-admin' => 'regress_user1', 'regress_user9' ],
|
|
qr/statement: CREATE ROLE regress_user9 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS ADMIN regress_user1;/,
|
|
'--with-admin');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--with-member' => 'regress_user1', 'regress_user10' ],
|
|
qr/statement: CREATE ROLE regress_user10 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS ROLE regress_user1;/,
|
|
'--with-member');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', '--role' => 'regress_user1', 'regress_user11' ],
|
|
qr/statement: CREATE ROLE regress_user11 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS IN ROLE regress_user1;/,
|
|
'--role');
|
|
$node->issues_sql_like(
|
|
[ 'createuser', 'regress_user12', '--member-of' => 'regress_user1' ],
|
|
qr/statement: CREATE ROLE regress_user12 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS IN ROLE regress_user1;/,
|
|
'--member-of');
|
|
|
|
$node->command_fails([ 'createuser', 'regress_user1' ],
|
|
'fails if role already exists');
|
|
$node->command_fails(
|
|
[
|
|
'createuser',
|
|
'regress_user1',
|
|
'--with-member' => 'regress_user2',
|
|
'regress_user3'
|
|
],
|
|
'fails for too many non-options');
|
|
|
|
done_testing();
|