Add Sanity/basic-functionality test
This commit is contained in:
parent
d19a479277
commit
ffa2f12487
4 changed files with 137 additions and 0 deletions
3
Sanity/basic-functionality/PURPOSE
Normal file
3
Sanity/basic-functionality/PURPOSE
Normal file
|
|
@ -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 <jprokes@redhat.com>
|
||||
18
Sanity/basic-functionality/main.fmf
Normal file
18
Sanity/basic-functionality/main.fmf
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
summary: Test basic functionality e.g. create databases/tables/roles, insert,update,
|
||||
etc.
|
||||
description: ''
|
||||
contact:
|
||||
- Vaclav Danek <vdanek@redhat.com>
|
||||
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
|
||||
102
Sanity/basic-functionality/runtest.sh
Executable file
102
Sanity/basic-functionality/runtest.sh
Executable file
|
|
@ -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 <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 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;
|
||||
14
Sanity/basic-functionality/transaction_test.sql
Normal file
14
Sanity/basic-functionality/transaction_test.sql
Normal file
|
|
@ -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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue