170_extensions.t 3.39 KB
Newer Older
1 2 3 4 5 6 7
# Check that all extensions install successfully.

use strict; 

use lib 't';
use TestLib;
use PgCommon;
8
use Test::More 0.87; # needs libtest-simple-perl backport on lenny
9

10 11
foreach my $v (@MAJORS) {
note "Running tests for $v";
12

13
if ($v < '9.1') {
14
    pass 'No extensions for version < 9.1';
15
    next;
16 17 18 19 20 21 22 23 24
}

# create cluster
is ((system "pg_createcluster $v main --start >/dev/null"), 0, "pg_createcluster $v main");

# plpgsql is installed by default; remove it to simplify test logic
is_program_out 'postgres', "psql -qc 'DROP EXTENSION plpgsql'", 0, '';
is_program_out 'postgres', "psql -Atc 'SELECT * FROM pg_extension'", 0, '';

25 26 27 28 29 30
my %depends = (
    earthdistance     => [qw(cube)],
    hstore_plperl     => [qw(hstore plperl)],
    hstore_plperlu    => [qw(hstore plperlu)],
    hstore_plpython2u => [qw(hstore plpython2u)],
    hstore_plpython3u => [qw(hstore plpython3u)],
31
    hstore_plpythonu  => [qw(hstore plpythonu)],
32 33
    jsonb_plperl      => [qw(plperl)],     # PG 11
    jsonb_plperlu     => [qw(plperlu)],    # PG 11
34 35 36
    jsonb_plpython2u  => [qw(plpython2u)], # PG 11
    jsonb_plpython3u  => [qw(plpython3u)], # PG 11
    jsonb_plpythonu   => [qw(plpythonu)],  # PG 11
37 38
    ltree_plpython2u  => [qw(ltree plpython2u)],
    ltree_plpython3u  => [qw(ltree plpython3u)],
39
    ltree_plpythonu   => [qw(ltree plpythonu)],
40 41 42 43
    # external extensions that might happen to be installed
    db2fce            => [qw(plpgsql)],
    pldbgapi          => [qw(plpgsql)],
    unit              => [qw(plpgsql)],
44 45
);

46 47 48 49 50
foreach (</usr/share/postgresql/$v/extension/*.control>) {
    my ($extname) = $_ =~ /^.*\/(.*)\.control$/;

    my $expected_extensions = "$extname\n";

51 52 53 54 55 56
    if ($depends{$extname}) {
        for my $dep (@{$depends{$extname}}) {
            is_program_out 'postgres', "psql -qc 'CREATE EXTENSION $dep'", 0, '',
                "$extname dependency $dep installs without error";
        }
        $expected_extensions = join ("\n", sort ($extname, @{$depends{$extname}})) . "\n";
57 58
    }

59 60
    if ($extname eq 'hstore' && $v eq '9.1') {
	# EXFAIL: hstore in 9.1 throws a warning about obsolete => operator
61 62
	like_program_out 'postgres', "psql -qc 'CREATE EXTENSION \"$extname\"'", 0,
	   qr/=>/, "extension $extname installs (with warning)";
63
    } elsif ($extname eq 'chkpass' && $v >= '9.5') {
64 65 66 67 68
        # chkpass is slightly broken, see
        # http://www.postgresql.org/message-id/20141117162116.GA3565@msg.df7cb.de
        like_program_out 'postgres', "psql -qc 'CREATE EXTENSION \"$extname\"'", 0,
            qr/WARNING:  type input function chkpass_in should not be volatile/,
            "extension $extname installs (with warning)";
69 70 71 72 73
    } else {
	is_program_out 'postgres', "psql -qc 'CREATE EXTENSION \"$extname\"'", 0, '',
	    "extension $extname installs without error";
    }

74
    is_program_out 'postgres', "psql -Atc 'SELECT extname FROM pg_extension ORDER BY extname'", 0,
75 76 77
	$expected_extensions, "$extname is in pg_extension";
    is_program_out 'postgres', "psql -qc 'DROP EXTENSION \"$extname\"'", 0, '',
	"extension $extname removes without error";
78 79 80 81 82 83

    if ($depends{$extname}) {
        for my $dep (@{$depends{$extname}}) {
            is_program_out 'postgres', "psql -qc 'DROP EXTENSION $dep'", 0, '',
                "$extname dependency extension $dep removes without error";
        }
84 85 86 87 88 89
    }
}

# clean up
is ((system "pg_dropcluster $v main --stop"), 0, "pg_dropcluster $v main");
check_clean;
90
}
91 92 93 94

done_testing();

# vim: filetype=perl