Skip to content

Commit

Permalink
Add PostGIS test generation from templates
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Sep 27, 2023
1 parent bc5642f commit f4e2c25
Show file tree
Hide file tree
Showing 32 changed files with 2,524 additions and 760 deletions.
50 changes: 50 additions & 0 deletions tests/postgis/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

declare -A versions=(
["10"]="3.0.9 3.1.9 3.2.5"
["11"]="3.0.9 3.1.9 3.2.5 3.3.4"
["12"]="3.0.9 3.1.9 3.2.5 3.3.4 3.4.0"
["13"]="3.1.9 3.2.5 3.3.4 3.4.0"
["14"]="3.1.9 3.2.5 3.3.4 3.4.0"
["15"]="3.1.9 3.2.5 3.3.4 3.4.0"
["16"]="3.4.0"
)

main() {
local pg

for pg in ${!versions[@]} ; do
generate "$pg"
done
}

generate() {
local pg="$1"
local template major_version short_version output

echo -e "Generating recipes for PostgreSQL $pg…\n"

for pstg in ${versions[$pg]} ; do
major_version=${pstg:0:3}
short_version=${major_version//./}
template="postgis${short_version}.template"
output="postgis${short_version}_${pg}.recipe"

if [[ ! -f "$template" ]] ; then
echo "$output: No template for PostGIS $major_version ($short_version)"
continue
fi

cat "$template" > "$output"
sed -i "s/%PG_VERSION%/$pg/g" "$output"
sed -i "s/%SHORT_VERSION%/$short_version/g" "$output"
sed -i "s/%MAJOR_VERSION%/$major_version/g" "$output"
sed -i "s/%FULL_VERSION%/$pstg/g" "$output"

echo "$output ($major_version)"
done

echo ""
}

main "$@"
91 changes: 91 additions & 0 deletions tests/postgis/postgis30.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Bibop recipe for PostGIS %MAJOR_VERSION% for PostgreSQL %PG_VERSION%
# See more: https://kaos.sh/bibop

################################################################################

pkg postgresql%PG_VERSION%-server postgis%SHORT_VERSION%_%PG_VERSION% postgis%SHORT_VERSION%_%PG_VERSION%-client postgis%SHORT_VERSION%_%PG_VERSION%-scripts postgis%SHORT_VERSION%_%PG_VERSION%-utils

require-root yes
unsafe-actions yes

var postgis_lib_version 3
var postgis_major_version %MAJOR_VERSION%
var postgis_version %FULL_VERSION%
var postgres_version %PG_VERSION%
var pkg_ver %SHORT_VERSION%_{postgres_version}

var postgres_service postgresql-{postgres_version}
var postgres_port 5432
var postgres_data_dir /var/lib/pgsql/{postgres_version}
var postgres_pid /var/run/postgresql{postgres_version}.pid

var data_dir /usr/pgsql-{postgres_version}/share
var lib_dir /usr/pgsql-{postgres_version}/lib
var bin_dir /usr/pgsql-{postgres_version}/bin

var utils_dir /usr/share/postgis{pkg_ver}

var contrib_dir {data_dir}/contrib/postgis-{postgis_major_version}
var extension_dir {data_dir}/extension

################################################################################

command "-" "Check libraries"
exist {lib_dir}/address_standardizer-{postgis_lib_version}.so
exist {lib_dir}/postgis-{postgis_lib_version}.so
exist {lib_dir}/postgis_raster-{postgis_lib_version}.so
exist {lib_dir}/postgis_topology-{postgis_lib_version}.so

mode {lib_dir}/address_standardizer-{postgis_lib_version}.so 755
mode {lib_dir}/postgis-{postgis_lib_version}.so 755
mode {lib_dir}/postgis_raster-{postgis_lib_version}.so 755
mode {lib_dir}/postgis_topology-{postgis_lib_version}.so 755

command "-" "Check linking with GDAL library"
lib-linked {lib_dir}/postgis_raster-{postgis_lib_version}.so libgdal.so.*

command "-" "Check data directories"
exist {contrib_dir}
dir {contrib_dir}
mode {contrib_dir} 755

exist {extension_dir}
dir {extension_dir}
mode {extension_dir} 755

command "-" "Check client binaries"
app pgsql2shp
app raster2pgsql
app shp2pgsql

link /bin/pgsql2shp {bin_dir}/postgis-{postgis_major_version}/pgsql2shp
link /bin/shp2pgsql {bin_dir}/postgis-{postgis_major_version}/shp2pgsql
link /bin/raster2pgsql {bin_dir}/postgis-{postgis_major_version}/raster2pgsql

################################################################################

command "service {postgres_service} initdb" "Database initialization"
exit 0

command "systemctl start {postgres_service}" "Start PostgreSQL server"
wait 1
wait-fs {postgres_pid}
service-works {postgres_service}
connect tcp :{postgres_port}

command "postgres:{bin_dir}/psql -t -c 'CREATE EXTENSION postgis;'" "Create PostGIS extension"
exit 0

command "postgres:{bin_dir}/psql -t -c 'SELECT PostGIS_Full_Version();'" "Check extension version"
exit 0
output-contains 'POSTGIS="{postgis_version} '

command "systemctl stop {postgres_service}" "Stop PostgreSQL server"
wait 1
!wait-fs {postgres_pid}
!service-works {postgres_service}

################################################################################

command:teardown "-" "Data cleanup"
cleanup {postgres_data_dir}/data
123 changes: 50 additions & 73 deletions tests/postgis/postgis30_10.recipe
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
# Bibop recipe for PostGIS 3.0 for PostgreSQL 10
# See more: https://kaos.sh/bibop

################################################################################

pkg postgresql10-server postgis30_10 postgis30_10-client postgis30_10-scripts postgis30_10-utils

fast-finish yes
require-root yes
unsafe-actions yes

var postgis_lib_version 3
var postgis_major_version 3.0
var postgis_version 3.0.9
var postgres_version 10
var pkg_ver 30_{postgres_version}

var postgres_service postgresql-{postgres_version}
var postgres_port 5432
var postgres_data_dir /var/lib/pgsql/{postgres_version}
var postgres_pid /var/run/postgresql{postgres_version}.pid

var postgis_lib_version 3
var postgis_major_version 3.0
var postgis_version 3.0.4
var postgres_version 10
var pkg_ver 30_10
var data_dir /usr/pgsql-{postgres_version}/share
var lib_dir /usr/pgsql-{postgres_version}/lib
var bin_dir /usr/pgsql-{postgres_version}/bin

var data_dir /usr/pgsql-{postgres_version}/share
var lib_dir /usr/pgsql-{postgres_version}/lib
var bin_dir /usr/pgsql-{postgres_version}/bin
var utils_dir /usr/share/postgis{pkg_ver}

var utils_dir /usr/share/postgis{pkg_ver}
var contrib_dir {data_dir}/contrib/postgis-{postgis_major_version}
var extension_dir {data_dir}/extension

var contrib_dir {data_dir}/contrib/postgis-{postgis_major_version}
var extension_dir {data_dir}/extension
################################################################################

command "-" "Check libraries"
exist {lib_dir}/address_standardizer-{postgis_lib_version}.so
Expand All @@ -32,8 +42,7 @@ command "-" "Check libraries"
mode {lib_dir}/postgis_topology-{postgis_lib_version}.so 755

command "-" "Check linking with GDAL library"
lib-linked {lib_dir}/postgis_raster-{postgis_lib_version}.so libgdal.so.28
!lib-linked {lib_dir}/postgis_raster-{postgis_lib_version}.so libgdal.so.1
lib-linked {lib_dir}/postgis_raster-{postgis_lib_version}.so libgdal.so.*

command "-" "Check data directories"
exist {contrib_dir}
Expand All @@ -44,36 +53,6 @@ command "-" "Check data directories"
dir {extension_dir}
mode {extension_dir} 755

command "-" "Check SQL files"
exist {contrib_dir}/legacy.sql
exist {contrib_dir}/legacy_gist.sql
exist {contrib_dir}/legacy_minimal.sql
exist {contrib_dir}/postgis.sql
exist {contrib_dir}/postgis_comments.sql
exist {contrib_dir}/postgis_proc_set_search_path.sql
exist {contrib_dir}/postgis_restore.pl
exist {contrib_dir}/postgis_upgrade.sql
exist {contrib_dir}/raster_comments.sql
exist {contrib_dir}/rtpostgis.sql
exist {contrib_dir}/rtpostgis_legacy.sql
exist {contrib_dir}/rtpostgis_proc_set_search_path.sql
exist {contrib_dir}/rtpostgis_upgrade.sql
exist {contrib_dir}/sfcgal_comments.sql
exist {contrib_dir}/spatial_ref_sys.sql
exist {contrib_dir}/topology.sql
exist {contrib_dir}/topology_comments.sql
exist {contrib_dir}/topology_upgrade.sql
exist {contrib_dir}/uninstall_legacy.sql
exist {contrib_dir}/uninstall_postgis.sql
exist {contrib_dir}/uninstall_rtpostgis.sql
exist {contrib_dir}/uninstall_topology.sql

exist {extension_dir}/address_standardizer--{postgis_version}.sql
exist {extension_dir}/postgis--{postgis_version}.sql
exist {extension_dir}/postgis_raster--{postgis_version}.sql
exist {extension_dir}/postgis_tiger_geocoder--{postgis_version}.sql
exist {extension_dir}/postgis_topology--{postgis_version}.sql

command "-" "Check client binaries"
app pgsql2shp
app raster2pgsql
Expand All @@ -83,32 +62,30 @@ command "-" "Check client binaries"
link /bin/shp2pgsql {bin_dir}/postgis-{postgis_major_version}/shp2pgsql
link /bin/raster2pgsql {bin_dir}/postgis-{postgis_major_version}/raster2pgsql

command "-" "Check scripts"
exist {utils_dir}/create_extension_unpackage.pl
exist {utils_dir}/create_spatial_ref_sys_config_dump.pl
exist {utils_dir}/create_undef.pl
exist {utils_dir}/create_unpackaged.pl
exist {utils_dir}/postgis_proc_set_search_path.pl
exist {utils_dir}/postgis_proc_upgrade.pl
exist {utils_dir}/postgis_restore.pl
exist {utils_dir}/profile_intersects.pl
exist {utils_dir}/read_scripts_version.pl
exist {utils_dir}/repo_revision.pl
exist {utils_dir}/test_estimation.pl
exist {utils_dir}/test_geography_estimation.pl
exist {utils_dir}/test_geography_joinestimation.pl
exist {utils_dir}/test_joinestimation.pl

mode {utils_dir}/create_spatial_ref_sys_config_dump.pl 755
mode {utils_dir}/create_undef.pl 755
mode {utils_dir}/create_unpackaged.pl 755
mode {utils_dir}/postgis_proc_set_search_path.pl 755
mode {utils_dir}/postgis_proc_upgrade.pl 755
mode {utils_dir}/postgis_restore.pl 755
mode {utils_dir}/profile_intersects.pl 755
mode {utils_dir}/read_scripts_version.pl 755
mode {utils_dir}/repo_revision.pl 755
mode {utils_dir}/test_estimation.pl 755
mode {utils_dir}/test_geography_estimation.pl 755
mode {utils_dir}/test_geography_joinestimation.pl 755
mode {utils_dir}/test_joinestimation.pl 755
################################################################################

command "service {postgres_service} initdb" "Database initialization"
exit 0

command "systemctl start {postgres_service}" "Start PostgreSQL server"
wait 1
wait-fs {postgres_pid}
service-works {postgres_service}
connect tcp :{postgres_port}

command "postgres:{bin_dir}/psql -t -c 'CREATE EXTENSION postgis;'" "Create PostGIS extension"
exit 0

command "postgres:{bin_dir}/psql -t -c 'SELECT PostGIS_Full_Version();'" "Check extension version"
exit 0
output-contains 'POSTGIS="{postgis_version} '

command "systemctl stop {postgres_service}" "Stop PostgreSQL server"
wait 1
!wait-fs {postgres_pid}
!service-works {postgres_service}

################################################################################

command:teardown "-" "Data cleanup"
cleanup {postgres_data_dir}/data
Loading

0 comments on commit f4e2c25

Please sign in to comment.