Skip to content

Commit cfe7bd1

Browse files
committed
Add new simple TAP test for tablespaces, attempt II.
See commit message for d1511fe. This new version attempts to fix path translation problem on MSYS/Windows. Discussion: https://postgr.es/m/20220117055326.GD756210%40rfd.leadboat.com
1 parent 5c649fe commit cfe7bd1

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Simple tablespace tests that can't be replicated on the same host
2+
# due to the use of absolute paths, so we keep them out of the regular
3+
# regression tests.
4+
5+
use strict;
6+
use warnings;
7+
use PostgreSQL::Test::Cluster;
8+
use PostgreSQL::Test::Utils;
9+
use Test::More tests => 20;
10+
11+
my $node = PostgreSQL::Test::Cluster->new('main');
12+
$node->init;
13+
$node->start;
14+
15+
# Create a couple of directories to use as tablespaces.
16+
my $basedir = $node->basedir();
17+
my $TS1_LOCATION = PostgreSQL::Test::Utils::perl2host("$basedir/ts1");
18+
$TS1_LOCATION =~ s/\/\.\//\//g; # collapse foo/./bar to foo/bar
19+
mkdir($TS1_LOCATION);
20+
my $TS2_LOCATION = PostgreSQL::Test::Utils::perl2host("$basedir/ts2");
21+
$TS2_LOCATION =~ s/\/\.\//\//g;
22+
mkdir($TS2_LOCATION);
23+
24+
my $result;
25+
26+
# Create a tablespace with an absolute path
27+
$result = $node->psql('postgres',
28+
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
29+
ok($result == 0, 'create tablespace with absolute path');
30+
31+
# Can't create a tablespace where there is one already
32+
$result = $node->psql('postgres',
33+
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
34+
ok($result != 0, 'clobber tablespace with absolute path');
35+
36+
# Create table in it
37+
$result = $node->psql('postgres',
38+
"CREATE TABLE t () TABLESPACE regress_ts1");
39+
ok($result == 0, 'create table in tablespace with absolute path');
40+
41+
# Can't drop a tablespace that still has a table in it
42+
$result = $node->psql('postgres',
43+
"DROP TABLESPACE regress_ts1");
44+
ok($result != 0, 'drop tablespace with absolute path');
45+
46+
# Drop the table
47+
$result = $node->psql('postgres', "DROP TABLE t");
48+
ok($result == 0, 'drop table in tablespace with absolute path');
49+
50+
# Drop the tablespace
51+
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1");
52+
ok($result == 0, 'drop tablespace with absolute path');
53+
54+
# Create two absolute tablespaces and two in-place tablespaces, so we can
55+
# testing various kinds of tablespace moves.
56+
$result = $node->psql('postgres',
57+
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
58+
ok($result == 0, 'create tablespace 1 with absolute path');
59+
$result = $node->psql('postgres',
60+
"CREATE TABLESPACE regress_ts2 LOCATION '$TS2_LOCATION'");
61+
ok($result == 0, 'create tablespace 2 with absolute path');
62+
$result = $node->psql('postgres',
63+
"SET allow_in_place_tablespaces=on; CREATE TABLESPACE regress_ts3 LOCATION ''");
64+
ok($result == 0, 'create tablespace 3 with in-place directory');
65+
$result = $node->psql('postgres',
66+
"SET allow_in_place_tablespaces=on; CREATE TABLESPACE regress_ts4 LOCATION ''");
67+
ok($result == 0, 'create tablespace 4 with in-place directory');
68+
69+
# Create a table and test moving between absolute and in-place tablespaces
70+
$result = $node->psql('postgres',
71+
"CREATE TABLE t () TABLESPACE regress_ts1");
72+
ok($result == 0, 'create table in tablespace 1');
73+
$result = $node->psql('postgres',
74+
"ALTER TABLE t SET tablespace regress_ts2");
75+
ok($result == 0, 'move table abs->abs');
76+
$result = $node->psql('postgres',
77+
"ALTER TABLE t SET tablespace regress_ts3");
78+
ok($result == 0, 'move table abs->in-place');
79+
$result = $node->psql('postgres',
80+
"ALTER TABLE t SET tablespace regress_ts4");
81+
ok($result == 0, 'move table in-place->in-place');
82+
$result = $node->psql('postgres',
83+
"ALTER TABLE t SET tablespace regress_ts1");
84+
ok($result == 0, 'move table in-place->abs');
85+
86+
# Drop everything
87+
$result = $node->psql('postgres',
88+
"DROP TABLE t");
89+
ok($result == 0, 'create table in tablespace 1');
90+
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1");
91+
ok($result == 0, 'drop tablespace 1');
92+
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts2");
93+
ok($result == 0, 'drop tablespace 2');
94+
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts3");
95+
ok($result == 0, 'drop tablespace 3');
96+
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts4");
97+
ok($result == 0, 'drop tablespace 4');
98+
99+
$node->stop;

0 commit comments

Comments
 (0)