Blob Blame History Raw
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/postgresql/Sanity/pg_repack
#   Description: Sanity test for pg_repackaudit extension
#   Author: Honza Horak <hhorak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2015 Red Hat, Inc.
#
#   This program is free software: you can redistribute it and/or
#   modify it under the terms of the GNU General Public License as
#   published by the Free Software Foundation, either version 2 of
#   the License, or (at your option) any later version.
#
#   This program is distributed in the hope that it will be
#   useful, but WITHOUT ANY WARRANTY; without even the implied
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#   PURPOSE.  See the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE="postgresql"

rlJournalStart
    rlPhaseStart FAIL "Setup"
        rlRun "rlImport database/postgresql"
        PACKAGES="$PACKAGES ${postgresqlPackagePrefix}pg_repack \
                  ${postgresqlPackagePrefix}${PACKAGE} \
                  ${postgresqlPackagePrefix}${PACKAGE}-contrib \
                  ${postgresqlPackagePrefix}${PACKAGE}-server";
        for PACKAGE in $PACKAGES; do
            rlAssertRpm $PACKAGE
        done
        rlRun "postgresqlStop";
        [[ -d ${postgresqlDataDir} ]] && rlFileBackup "${postgresqlDataDir}"
        rlRun "postgresqlCleanup"
        rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
        rlRun "pushd $TmpDir"
        rlRun "postgresqlStart"
    rlPhaseEnd

    rlPhaseStartTest
        rlRun "postgresqlQuery \"DROP EXTENSION IF EXISTS pg_repack;\"";
        rlRun "postgresqlQuery \"CREATE DATABASE testrepack;\"" 0;
        rlRun "postgresqlQuery \"CREATE EXTENSION pg_repack;\" testrepack" 0;
        rlRun "postgresqlExec 'pgbench -i -s 50 testrepack' postgres"
        rlRun "postgresqlExec 'pg_repack --no-order --table pgbench_accounts testrepack -e' postgres"
        rlRun "postgresqlQuery \"DROP EXTENSION pg_repack;\" testrepack";
        rlRun "postgresqlQuery \"DROP DATABASE testrepack;\"" 0;
    rlPhaseEnd

    rlPhaseStart WARN "Cleanup";
        rm -f $rlRun_LOG;
        rlRun "postgresqlCleanup";
        rlFileRestore;
        rlRun "popd"
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd