add postgresql-test-rpm-macros

This commit is contained in:
daidai_is_here 2020-04-08 18:35:13 +08:00
parent 9168672211
commit 8ce55029e2
4 changed files with 244 additions and 1 deletions

9
macros.postgresql Normal file
View File

@ -0,0 +1,9 @@
# Macros from this file should exist on system only once, so it package
# maintainer's responsibility to guarantee that all packages which install
# these macros collide, or that (during package-build time) only one such
# package is installed (e.g. similarly to %%scl macro defined installed by
# *-build subpackage).
%postgresql_major 10
%postgresql_module_requires Requires: postgresql-server(:MODULE_COMPAT_10)

18
macros.postgresql-test Normal file
View File

@ -0,0 +1,18 @@
# Initialize the PostgreSQL tests environment. This is supposed to be invoked
# in prep/build/install (where you plan to run the testsuite), while it defines
# several useful shell variables and provies useful commands. Effect of this
# command end with shell exit.
%postgresql_tests_init . "/usr/share/postgresql-setup/postgresql_pkg_tests.sh"
# Start the testing postgresql server, setting the actual unix user to be the
# PostgreSQL admin. The $PGHOST/$PGPORT are set appropriately, so psql is able
# to run without passwords. This also sets shell exit trap callback so that if
# something goes wrong and package build fails, the temporary database is
# automatically cleaned up.
%postgresql_tests_start pgtests_start
# Initialize database and run server in one step, if this works well-enough.
%postgresql_tests_run %postgresql_tests_init ; %postgresql_tests_start
%pgtests_init echo 2>&1 WARN: macro pgtests_init will be removed, use postgresql_tests_init ; %postgresql_tests_init
%pgtests_start echo 2>&1 WARN: macro pgtests_start will be removed, use postgresql_tests_start ; %postgresql_tests_start

View File

@ -4,7 +4,7 @@
Name: postgresql
Version: 10.5
Release: 13
Release: 14
Summary: PostgreSQL client programs
License: PostgreSQL
URL: http://www.postgresql.org/
@ -19,6 +19,9 @@ Source8: postgresql-setup
Source9: postgresql.service
# https://github.com/devexp-db/postgresql-setup/blob/master/share/postgresql-setup/library.sh.in
Source10: library.sh
Source11: macros.postgresql
Source12: macros.postgresql-test
Source13: postgresql_pkg_tests.sh
Patch0000: 0000-postgresql-var-run-socket.patch
Patch0001: 0000-rpm-pgsql.patch
@ -139,6 +142,15 @@ Requires: %{name}-server = %{version}-%{release} %{name}-devel = %{version}-%{re
The postgresql-test package contains files needed for various tests for the
PostgreSQL database management system, including regression tests and benchmarks.
%package test-rpm-macros
Summary: Convenience RPM macros for build-time testing against PostgreSQL server
Requires: %{name}-server = %{version}-%{release}
%description test-rpm-macros
This package is meant to be added as BuildRequires: dependency of other packages
that want to run build-time testsuite against running PostgreSQL server.
%prep
(
cd "$(dirname "%{SOURCE0}")"
@ -257,6 +269,9 @@ install -D %{SOURCE7} $RPM_BUILD_ROOT%{_libexecdir}/postgresql-check-db-dir
install %{SOURCE8} $RPM_BUILD_ROOT%{_bindir}/postgresql-setup
install -Dm 0644 %{SOURCE9} $RPM_BUILD_ROOT%{_unitdir}/postgresql.service
install -D %{SOURCE10} $RPM_BUILD_ROOT%{_datadir}/postgresql-setup/library.sh
install -Dm 0644 %{SOURCE11} $RPM_BUILD_ROOT%{macrosdir}/macros.postgresql
install -m 0644 %{SOURCE12} $RPM_BUILD_ROOT%{macrosdir}/macros.postgresql-test
install %{SOURCE13} $RPM_BUILD_ROOT%{_datadir}/postgresql-setup/postgresql_pkg_tests.sh
install -d $RPM_BUILD_ROOT%{_libdir}/pgsql/test
cp -a src/test/regress $RPM_BUILD_ROOT%{_libdir}/pgsql/test
@ -385,11 +400,15 @@ find_lang_bins pltcl.lst pltcl
%{_bindir}/{ecpg,pg_config}
%{_libdir}/{pgsql/pgxs/,pkgconfig/*.pc}
%{_libdir}/{libecpg,libecpg_compat,libpgtypes,libpq}.so
%{macrosdir}/macros.postgresql
%files static
%{_libdir}/libpgcommon.a
%{_libdir}/libpgport.a
%files test-rpm-macros
%{_datadir}/postgresql-setup/postgresql_pkg_tests.sh
%{macrosdir}/macros.postgresql-test
%files plperl -f plperl.lst
%{_datadir}/pgsql/extension/plperl*
@ -409,6 +428,10 @@ find_lang_bins pltcl.lst pltcl
%attr(-,postgres,postgres) %{_libdir}/pgsql/test
%changelog
* Tue Apr 08 2020 daiqianwen <daiqianwen@huawei.com> - 10.5-14
- Type: enhancement
- DESC: add postgresql-test-rpm-macros
* Tue Apr 07 2020 daiqianwen <daiqianwen@huawei.com> - 10.5-13
- Type: enhancement
- DESC: delete unseless tarball

193
postgresql_pkg_tests.sh Normal file
View File

@ -0,0 +1,193 @@
#! /bin/sh
# Do some "integration" testing against running PostgreSQL server.
# This file is to be sourced.
try_random_port ()
{
_port=$RANDOM
if test -n "$_port" && eval '_port=$(( $_port + 32000 ))' 2>/dev/null; then
echo "$_port"
elif test -x /usr/bin/shuf; then
/usr/bin/shuf -r -n 1 -i 32000-64767
else
echo 54321
fi
}
: ${PGTESTS_DATADIR=`pwd`/datadir}
: ${PGTESTS_ADMIN=`id -u -n`}
: ${PGTESTS_ADMINDB=$PGTESTS_ADMIN}
: ${PGTESTS_ADMINPASS=$PGTESTS_ADMIN}
: ${PGTESTS_PORT=`try_random_port`}
: ${PGTESTS_SOCKETDIR=/tmp}
: ${PGTESTS_USERS=test:test}
: ${PGTESTS_DATABASES=test:test}
# Stop the old cluster and/or remove it's data.
: ${PGTESTS_STARTCLEANUP=:}
# Cleanup once we exit the script.
: ${PGTESTS_CLEANUP=:}
# Cleanup once we exit the script.
: ${PGTESTS_CLEANUP=:}
export PGPORT=$PGTESTS_PORT
export PGHOST=$PGTESTS_SOCKETDIR
:
warning ()
{
echo >&2 " ! $*"
}
__trap_cb ()
{
IFS=' '
for __func in $__TRAP_ACTIONS
do
$__func
done
}
trap __trap_cb EXIT
__pgtests_initdb ()
{
initdb "$PGTESTS_DATADIR" -U "$PGTESTS_ADMIN" \
--auth-local=peer --auth-host=md5 \
${PGTESTS_LOCALE+--locale="$PGTESTS_LOCALE"}
}
__pgtests_start ()
{
pg_ctl -D "$PGTESTS_DATADIR" -l "$PGTESTS_DATADIR"/start.log start \
-o "-k $PGTESTS_SOCKETDIR -p $PGTESTS_PORT" -w || {
cat >&2 "$PGTESTS_DATADIR"/start.log
false
}
}
__pgtests_create_admins_db ()
{
createdb -h "$PGTESTS_SOCKETDIR" "$PGTESTS_ADMINDB" --owner "$PGTESTS_ADMIN" -p "$PGTESTS_PORT"
}
__pgtests_passwd()
{
psql -d postgres --set=user="$1" --set=pass="$2" -tA \
<<<"ALTER USER :\"user\" WITH ENCRYPTED PASSWORD :'pass';"
}
pgtests_start ()
{
unset __TRAP_ACTIONS
if $PGTESTS_STARTCLEANUP; then
# We don't plan to be serious here. This pgtests_* effort is just to
# ease _testing_ against running postgresql server without too much
# writing.
if test -f "$PGTESTS_DATADIR"/postmaster.pid; then
# Give it a try.
warning "Seems like server works, trying to stop."
pg_ctl stop -D "$PGTESTS_DATADIR" -w
fi
# Cleanup testing directory
if test -e "$PGTESTS_DATADIR"; then
warning "Removing old data directory."
rm -r "$PGTESTS_DATADIR"
fi
fi
__pgtests_initdb
__TRAP_ACTIONS="pgtests_cleanup $__TRAP_ACTIONS"
__pgtests_start
__TRAP_ACTIONS="pgtests_stop $__TRAP_ACTIONS"
__pgtests_create_admins_db
__pgtests_passwd "$PGTESTS_ADMIN" "$PGTESTS_ADMINPASS"
for _pgt_user in $PGTESTS_USERS
do
save_IFS=$IFS
IFS=:
_user=
_pass=
for _part in $_pgt_user
do
if test -z "$_user"; then
_user=$_part
else
_pass=$_part
fi
done
createuser "$_user"
__pgtests_passwd "$_user" "$_pass"
IFS=$save_IFS
done
for _pgt_db in $PGTESTS_DATABASES
do
save_IFS=$IFS
IFS=:
_db=
_user=
for _part in $_pgt_db
do
if test -z "$_user"; then
_user=$_part
else
_db=$_part
fi
done
createdb "$_db" --owner "$_part"
IFS=$save_IFS
done
}
__clean_trap_action ()
{
__new_actions=
for __action in $__TRAP_ACTIONS
do
if test "$__action" = "$1"; then
:
else
__new_actions="$__action $__new_actions"
fi
done
__TRAP_ACTIONS=$__new_actions
}
pgtests_cleanup ()
{
if $PGTESTS_CLEANUP && $PGTESTS_AUTOSTOP; then
rm -r "$PGTESTS_DATADIR"
fi
__clean_trap_action pgtests_cleanup
}
pgtests_stop ()
{
if $PGTESTS_AUTOSTOP; then
pg_ctl stop -D "$PGTESTS_DATADIR" -w
fi
__clean_trap_action pgtests_stop
}