mirror of
https://github.com/postgres/postgres.git
synced 2025-10-21 02:52:47 +03:00
The TAP tests whose ok() calls are changed in this commit were relying on perl operators, rather than equivalents available in Test::More. For example, rather than the following: ok($data =~ qr/expr/m, "expr matching"); ok($data !~ qr/expr/m, "expr not matching"); The new test code uses this equivalent: like($data, qr/expr/m, "expr matching"); unlike($data, qr/expr/m, "expr not matching"); A huge benefit of the new formulation is that it is possible to know about the values we are checking if a failure happens, making debugging easier, should the test runs happen in the buildfarm, in the CI or locally. This change leads to more test code overall as perltidy likes to make the code pretty the way it is in this commit. Author: Sadhuprasad Patro <b.sadhu@gmail.com> Discussion: https://postgr.es/m/CAFF0-CHhwNx_Cv2uy7tKjODUbeOgPrJpW4Rpf1jqB16_1bU2sg@mail.gmail.com
99 lines
3.7 KiB
Perl
99 lines
3.7 KiB
Perl
|
|
# Copyright (c) 2024-2025, PostgreSQL Global Development Group
|
|
|
|
# Simple tablespace tests that can't be replicated on the same host
|
|
# due to the use of absolute paths, so we keep them out of the regular
|
|
# regression tests.
|
|
|
|
use strict;
|
|
use warnings FATAL => 'all';
|
|
use PostgreSQL::Test::Cluster;
|
|
use PostgreSQL::Test::Utils;
|
|
use Test::More;
|
|
|
|
my $node = PostgreSQL::Test::Cluster->new('main');
|
|
$node->init;
|
|
$node->start;
|
|
|
|
# Create a couple of directories to use as tablespaces.
|
|
my $basedir = $node->basedir();
|
|
my $TS1_LOCATION = "$basedir/ts1";
|
|
$TS1_LOCATION =~ s/\/\.\//\//g; # collapse foo/./bar to foo/bar
|
|
mkdir($TS1_LOCATION);
|
|
my $TS2_LOCATION = "$basedir/ts2";
|
|
$TS2_LOCATION =~ s/\/\.\//\//g;
|
|
mkdir($TS2_LOCATION);
|
|
|
|
my $result;
|
|
|
|
# Create a tablespace with an absolute path
|
|
$result = $node->psql('postgres',
|
|
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
|
|
is($result, 0, 'create tablespace with absolute path');
|
|
|
|
# Can't create a tablespace where there is one already
|
|
$result = $node->psql('postgres',
|
|
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
|
|
isnt($result, 0, 'clobber tablespace with absolute path');
|
|
|
|
# Create table in it
|
|
$result = $node->psql('postgres', "CREATE TABLE t () TABLESPACE regress_ts1");
|
|
is($result, 0, 'create table in tablespace with absolute path');
|
|
|
|
# Can't drop a tablespace that still has a table in it
|
|
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1");
|
|
isnt($result, 0, 'drop tablespace with absolute path');
|
|
|
|
# Drop the table
|
|
$result = $node->psql('postgres', "DROP TABLE t");
|
|
is($result, 0, 'drop table in tablespace with absolute path');
|
|
|
|
# Drop the tablespace
|
|
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1");
|
|
is($result, 0, 'drop tablespace with absolute path');
|
|
|
|
# Create two absolute tablespaces and two in-place tablespaces, so we can
|
|
# testing various kinds of tablespace moves.
|
|
$result = $node->psql('postgres',
|
|
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
|
|
is($result, 0, 'create tablespace 1 with absolute path');
|
|
$result = $node->psql('postgres',
|
|
"CREATE TABLESPACE regress_ts2 LOCATION '$TS2_LOCATION'");
|
|
is($result, 0, 'create tablespace 2 with absolute path');
|
|
$result = $node->psql('postgres',
|
|
"SET allow_in_place_tablespaces=on; CREATE TABLESPACE regress_ts3 LOCATION ''"
|
|
);
|
|
is($result, 0, 'create tablespace 3 with in-place directory');
|
|
$result = $node->psql('postgres',
|
|
"SET allow_in_place_tablespaces=on; CREATE TABLESPACE regress_ts4 LOCATION ''"
|
|
);
|
|
is($result, 0, 'create tablespace 4 with in-place directory');
|
|
|
|
# Create a table and test moving between absolute and in-place tablespaces
|
|
$result = $node->psql('postgres', "CREATE TABLE t () TABLESPACE regress_ts1");
|
|
is($result, 0, 'create table in tablespace 1');
|
|
$result = $node->psql('postgres', "ALTER TABLE t SET tablespace regress_ts2");
|
|
is($result, 0, 'move table abs->abs');
|
|
$result = $node->psql('postgres', "ALTER TABLE t SET tablespace regress_ts3");
|
|
is($result, 0, 'move table abs->in-place');
|
|
$result = $node->psql('postgres', "ALTER TABLE t SET tablespace regress_ts4");
|
|
is($result, 0, 'move table in-place->in-place');
|
|
$result = $node->psql('postgres', "ALTER TABLE t SET tablespace regress_ts1");
|
|
is($result, 0, 'move table in-place->abs');
|
|
|
|
# Drop everything
|
|
$result = $node->psql('postgres', "DROP TABLE t");
|
|
is($result, 0, 'create table in tablespace 1');
|
|
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1");
|
|
is($result, 0, 'drop tablespace 1');
|
|
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts2");
|
|
is($result, 0, 'drop tablespace 2');
|
|
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts3");
|
|
is($result, 0, 'drop tablespace 3');
|
|
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts4");
|
|
is($result, 0, 'drop tablespace 4');
|
|
|
|
$node->stop;
|
|
|
|
done_testing();
|