130_nonroot_admin.t 1.75 KB
Newer Older
1 2 3 4 5 6 7 8
# Check that cluster administration works as non-root if the invoker has
# sufficient permissions on directories.

use strict; 

use lib 't';
use TestLib;

9 10
my $version = $MAJORS[-1];
my $oldversion = $MAJORS[0];
11

12
use Test::More tests => 22;
13 14 15 16 17
use PgCommon;

my $testuser = 'postgres';

# pg_createcluster and pg_ctlcluster
18
is ((exec_as $testuser, "pg_createcluster $version main --start"), 0,
19 20
    "pg_createcluster succeeds as user $testuser with appropriate owner permissions");

21
like_program_out $testuser, 'pg_lsclusters -h', 0, qr/^$version\s+main.*online/m;
22 23 24
like_program_out 'postgres', 'psql -Atl', 0, qr/template1.*UTF8/;

# pg_dropcluster
25
is ((exec_as $testuser, "pg_dropcluster $version main --stop"), 0,
26 27 28
    "pg_dropcluster succeeds as user $testuser with appropriate directory owner permissions");

# pg_upgradecluster
29 30 31 32 33
SKIP: {
    skip 'Only one major version installed, skipping pg_upgradecluster tests', 8 if ($oldversion eq $version);

    is ((exec_as $testuser, "pg_createcluster $oldversion main --start"), 0,
        "pg_createcluster succeeds as user $testuser with appropriate group permissions");
34
    my $outref;
35
    is ((exec_as $testuser, "pg_upgradecluster -v $version $oldversion main", $outref, 0), 0, 
36 37 38 39 40
        "pg_upgradecluster succeeds as user $testuser");
    like $$outref, qr/Starting target cluster/, 'pg_upgradecluster reported cluster startup';
    like $$outref, qr/Success. Please check/, 'pg_upgradecluster reported successful operation';

    like_program_out $testuser, 'pg_lsclusters -h', 0,
41
        qr/^$oldversion\s+main.*down.*\n^$version\s+main.*online/m;
42 43

    # clean up
44 45
    is ((exec_as $testuser, "pg_dropcluster $oldversion main"), 0);
    is ((exec_as $testuser, "pg_dropcluster $version main --stop"), 0);
46 47 48 49 50
}

check_clean;

# vim: filetype=perl