103 lines
4.6 KiB
Bash
Executable file
103 lines
4.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
#
|
|
# runtest.sh of /CoreOS/postgresql/Sanity/basic-functionality
|
|
# Description: Test basic functionality e.g. create databases/tables/roles, insert,update, etc.
|
|
# Author: Jakub Prokes <jprokes@redhat.com>
|
|
#
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
#
|
|
# Copyright (c) 2013 Red Hat, Inc. All rights reserved.
|
|
#
|
|
# This copyrighted material is made available to anyone wishing
|
|
# to use, modify, copy, or redistribute it subject to the terms
|
|
# and conditions of the GNU General Public License version 2.
|
|
#
|
|
# 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, write to the Free
|
|
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
# Boston, MA 02110-1301, USA.
|
|
#
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# Include Beaker environment
|
|
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
|
|
|
PACKAGE="postgresql-server"
|
|
|
|
function onError() {
|
|
[[ $? -eq 127 ]] && rlFail "Command not found, probably typo in test.";
|
|
}
|
|
|
|
trap "onError;" ERR
|
|
|
|
function varDump() {
|
|
rlLogDebug "\$${1}='${!1}'";
|
|
}
|
|
|
|
rlJournalStart
|
|
rlPhaseStartSetup "General"
|
|
rlRun "rlImport database/postgresql"
|
|
PACKAGES="$PACKAGES ${postgresqlPackagePrefix}${PACKAGE}"
|
|
for PACKAGE in $PACKAGES; do
|
|
rlAssertRpm $PACKAGE
|
|
done
|
|
rlPhaseEnd
|
|
|
|
rlPhaseStartSetup "Database setup"
|
|
varDump postgresqlDataDir;
|
|
[[ -d $postgresqlDataDir ]] && rlFileBackup $postgresqlDataDir;
|
|
postgresqlCleanup;
|
|
postgresqlInitDB;
|
|
rlRun "postgresqlChangeAuth trust" 0 "Allow 'trust' authentication"
|
|
#rlRun "sed -i -e 's/ident/trust/' ${postgresqlDataDir}/pg_hba.conf" 0 "Allow 'trust' authentication"
|
|
cat /var/lib/pgsql/data/pg_hba.conf
|
|
postgresqlStart;
|
|
rlPhaseEnd
|
|
|
|
rlPhaseStartTest "Create & Grant"
|
|
dbName="fOo";
|
|
userName="johndoe";
|
|
tableName="test_table";
|
|
rlLog "$FUNCNAME"
|
|
rlRun "postgresqlUDB $dbName $userName bar" 0 "Create DB $dbName and user $userName"
|
|
rlRun "postgresqlQuery \"\\\l\" | grep -q $dbName" 0 "Database $dbName exist";
|
|
rlRun "postgresqlQuery \"\\\du\" | grep -q \"$userName\"" 0 "User $userName exist";
|
|
rlRun "postgresqlExec 'psql -f ./grant.sql' postgres";
|
|
rlRun "psql -h localhost -U johndoe -d \"$dbName\" -c \"CREATE TABLE $tableName (id bigserial primary key,fakedata varchar(20),toDelete boolean);\"" 0 "Create table $tableName";
|
|
rlRun "postgresqlQuery \"\\\d\" \"$dbName\" | cut -d '|' -f 2 | tr -d '[:blank:]' | grep -qE \"^${tableName}$\"" 0 "Table $tableName exist";
|
|
rlPhaseEnd
|
|
|
|
rlPhaseStartTest "Insert/Select/Updated/Delete"
|
|
iCount=1000;
|
|
for ((i=0; i<$iCount; i++)); do
|
|
psql -h localhost -U johndoe -d "$dbName" -c "INSERT INTO $tableName (fakedata,toDelete) VALUES ('tramtarada',false);" &>/dev/null;
|
|
[[ $(( $i % 100 )) -eq 0 ]] && rlLog "$i inserts done";
|
|
done;
|
|
rlAssertEquals "Number of lines corresponds number of inserts" $(psql -t -h localhost -U johndoe -d "$dbName" -c "SELECT count(*) FROM $tableName;") $iCount;
|
|
rlRun "psql -h localhost -U johndoe -d \"$dbName\" -c \"UPDATE $tableName SET toDelete=true WHERE (id % 2) = 0;\"" 0 "UPDATE";
|
|
rlAssertEquals "Number of changed lines corresponds expectation" $(psql -t -h localhost -U johndoe -d "$dbName" -c "SELECT count(*) FROM $tableName WHERE toDelete=true;") $(( $iCount / 2));
|
|
rlRun "psql -h localhost -U johndoe -d \"$dbName\" -c \"DELETE FROM $tableName WHERE toDelete = true;\"" 0 "DELETE";
|
|
rlAssertEquals "New count of lines corresponds expectation" $(psql -t -h localhost -U johndoe -d "$dbName" -c "SELECT count(*) FROM $tableName;") $(( $iCount / 2));
|
|
rlPhaseEnd
|
|
|
|
rlPhaseStartTest "Transaction"
|
|
rlRun -l "psql -e -h localhost -U johndoe -d \"$dbName\" -f ./transaction_test.sql";
|
|
rlAssertEquals "New count of lines corresponds expectation" $(psql -t -h localhost -U johndoe -d "$dbName" -c "SELECT count(*) FROM $tableName;") $(( $iCount / 2));
|
|
rlPhaseEnd
|
|
|
|
rlPhaseStartCleanup
|
|
postgresqlCleanup;
|
|
rlFileRestore;
|
|
rlServiceRestore $postgresqlServiceName;
|
|
rlPhaseEnd
|
|
rlJournalPrintText
|
|
rlJournalEnd
|
|
|
|
trap ERR;
|