diff --git a/Sanity/basic-functionality/PURPOSE b/Sanity/basic-functionality/PURPOSE new file mode 100644 index 0000000..2d6ab08 --- /dev/null +++ b/Sanity/basic-functionality/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/postgresql/Sanity/basic-functionality +Description: Test basic functionality e.g. create databases/tables/roles, insert,update, etc. +Author: Jakub Prokes diff --git a/Sanity/basic-functionality/main.fmf b/Sanity/basic-functionality/main.fmf new file mode 100644 index 0000000..994aa22 --- /dev/null +++ b/Sanity/basic-functionality/main.fmf @@ -0,0 +1,18 @@ +summary: Test basic functionality e.g. create databases/tables/roles, insert,update, + etc. +description: '' +contact: +- Vaclav Danek +component: +- postgresql +test: ./runtest.sh +path: /Sanity/basic-functionality +framework: beakerlib +require: +- library(postgresql/basic) +recommend: +- postgresql +- postgresql-server +duration: 30m +enabled: true +extra-task: /CoreOS/postgresql/Sanity/basic-functionality diff --git a/Sanity/basic-functionality/runtest.sh b/Sanity/basic-functionality/runtest.sh new file mode 100755 index 0000000..66129f0 --- /dev/null +++ b/Sanity/basic-functionality/runtest.sh @@ -0,0 +1,102 @@ +#!/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 +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# 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 postgresql/basic" + 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 "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; diff --git a/Sanity/basic-functionality/transaction_test.sql b/Sanity/basic-functionality/transaction_test.sql new file mode 100644 index 0000000..0febe47 --- /dev/null +++ b/Sanity/basic-functionality/transaction_test.sql @@ -0,0 +1,14 @@ +SELECT count(*) FROM test_table; + +BEGIN; +UPDATE test_table SET fakedata='divisible by 3' WHERE (id % 3) = 0; +UPDATE test_table SET fakedata='divisible by 5' WHERE (id % 5) = 0; +UPDATE test_table SET fakedata='divisible by 7' WHERE (id % 7) = 0; +COMMIT; + +SELECT * FROM test_table ORDER BY id LIMIT 10; + +BEGIN; +UPDATE test_table SET toDelete = true WHERE id < 100; +DELETE FROM test_table WHERE toDelete = true; +ROLLBACK;