Skip to content

Commit

Permalink
Reorder tests sources to match order of tests in TEST_LIST
Browse files Browse the repository at this point in the history
  • Loading branch information
SlouchyButton authored and phracek committed Nov 20, 2024
1 parent fe6e2e8 commit f4d56eb
Showing 1 changed file with 130 additions and 130 deletions.
260 changes: 130 additions & 130 deletions test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -658,32 +658,19 @@ VERY_LONG_IDENTIFIER="very_long_identifier_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
return $ret
}

# run_replication_test
# run_general_tests
# --------------------
# Start two containers one as main, one as secondary. Checks whether the main
# sees secondary server connected. Tries to create data on main server and
# checks whether they are correctly replicated to secondary server.
function run_replication_test() {
local DB=postgres
local PGUSER=master
local PASS=master
# Tests different combinations of parameters and that they work. Also tests SCL
# usage. Tries to actually SELECT something from the database.
function run_general_tests() {
local ret=0

echo "Testing master-slave replication"
local cluster_args="-e POSTGRESQL_ADMIN_PASSWORD=pass -e POSTGRESQL_MASTER_USER=$PGUSER -e POSTGRESQL_MASTER_PASSWORD=$PASS"
local cid_suffix="basic"
local master_ip=
local slave_cids=

# Setup the cluster
setup_replication_cluster || ret=1

# Check if the master knows about the slaves
CONTAINER_IP=$master_ip
test_slave_visibility || ret=2

# Do some real work to test replication in practice
table_name="t1" test_value_replication || ret=3
PGUSER=user PASS=pass POSTGRESQL_MAX_CONNECTIONS=42 POSTGRESQL_MAX_PREPARED_TRANSACTIONS=42 POSTGRESQL_SHARED_BUFFERS=64MB run_tests no_admin || ret=1
PGUSER=user1 PASS=pass1 ADMIN_PASS=r00t run_tests admin || ret=2
DB=postgres ADMIN_PASS=r00t run_tests only_admin || ret=3
# Test with arbitrary uid for the container
DOCKER_ARGS="-u 12345" PGUSER=user2 PASS=pass run_tests no_admin_altuid || ret=4
DOCKER_ARGS="-u 12345" PGUSER=user3 PASS=pass1 ADMIN_PASS=r00t run_tests admin_altuid || ret=5
DB=postgres DOCKER_ARGS="-u 12345" ADMIN_PASS=rOOt run_tests only_admin_altuid || ret=6
if [ $ret -eq 0 ]; then
echo " Success!"
fi
Expand Down Expand Up @@ -770,74 +757,32 @@ $volume_options
return $ret
}

# run_upgrade_test
# run_replication_test
# --------------------
# Testing upgrade from previous version to current version using
# POSTGRESQL_UPGRADE env variable. Checks that upgrade is successfull using two
# demo databases (simple and pagila)
run_upgrade_test ()
{
# Start two containers one as main, one as secondary. Checks whether the main
# sees secondary server connected. Tries to create data on main server and
# checks whether they are correctly replicated to secondary server.
function run_replication_test() {
local DB=postgres
local PGUSER=master
local PASS=master
local ret=0

local upgrade_path= prev= act=
case $OS in
rhel8)
upgrade_path="none 12 13 15 16 none"
;;
rhel9|c9s)
upgrade_path="none 13 15 16 none"
;;
rhel10|c10s)
upgrade_path="none 13 15 16 none"
;;
fedora)
upgrade_path="none 12 13 14 15 16 none"
;;
*)
echo "unsupported OS variable" >&2
return 1
;;
esac

for act in $upgrade_path; do
if test "$act" = $VERSION; then
break
fi
prev=$act
done
test "$prev" != none || return 0
# Check if the previous image is available in the registry
docker pull "$(get_image_id "$prev:remote")" || return 0

# TODO: We run this script from $VERSION directory, through test/run symlink.
test/run_upgrade_test "$prev:remote" "$VERSION:local" || ret=1
if [ $ret -eq 0 ]; then
echo " Success!"
fi
return $ret
}
echo "Testing master-slave replication"
local cluster_args="-e POSTGRESQL_ADMIN_PASSWORD=pass -e POSTGRESQL_MASTER_USER=$PGUSER -e POSTGRESQL_MASTER_PASSWORD=$PASS"
local cid_suffix="basic"
local master_ip=
local slave_cids=

# run_migration_test
# --------------------
# Testing migration from each supported version to currently tested one. Pagila
# is used as a demo database - data integrity is checked. Asserts that no
# invalid options can be passed without container failing to start.
run_migration_test ()
{
local ret=0
[ "${OS}" == "fedora" ] && return 0
# Setup the cluster
setup_replication_cluster || ret=1

local from_version
local upgrade_path="12 13 15 16"
# Check if the master knows about the slaves
CONTAINER_IP=$master_ip
test_slave_visibility || ret=2

for from_version in $upgrade_path; do
# Do not test migration from $VERSION:remote to $VERSION:local
test $(version2number $from_version) -lt $(version2number "$VERSION") \
|| break
# Skip if the previous image is not available in the registry
docker pull "$(get_image_id "$from_version:remote")" || continue
test/run_migration_test $from_version:remote $VERSION:local || ret=1
done
# Do some real work to test replication in practice
table_name="t1" test_value_replication || ret=3
if [ $ret -eq 0 ]; then
echo " Success!"
fi
Expand Down Expand Up @@ -873,25 +818,6 @@ run_s2i_test() {
return $ret
}

# run_general_tests
# --------------------
# Tests different combinations of parameters and that they work. Also tests SCL
# usage. Tries to actually SELECT something from the database.
function run_general_tests() {
local ret=0
PGUSER=user PASS=pass POSTGRESQL_MAX_CONNECTIONS=42 POSTGRESQL_MAX_PREPARED_TRANSACTIONS=42 POSTGRESQL_SHARED_BUFFERS=64MB run_tests no_admin || ret=1
PGUSER=user1 PASS=pass1 ADMIN_PASS=r00t run_tests admin || ret=2
DB=postgres ADMIN_PASS=r00t run_tests only_admin || ret=3
# Test with arbitrary uid for the container
DOCKER_ARGS="-u 12345" PGUSER=user2 PASS=pass run_tests no_admin_altuid || ret=4
DOCKER_ARGS="-u 12345" PGUSER=user3 PASS=pass1 ADMIN_PASS=r00t run_tests admin_altuid || ret=5
DB=postgres DOCKER_ARGS="-u 12345" ADMIN_PASS=rOOt run_tests only_admin_altuid || ret=6
if [ $ret -eq 0 ]; then
echo " Success!"
fi
return $ret
}

# run_test_cfg_hook
# --------------------
# Checks whether using config files in persistent mounted volume works. Also
Expand Down Expand Up @@ -932,6 +858,28 @@ run_test_cfg_hook()
return $ret
}

# run_s2i_bake_data_test
# --------------------
# Testing pre-start script and `init.sql` file with prefilled data placed in S2I
# resulting image.
run_s2i_bake_data_test ()
{
local s2i_image_name="$IMAGE_NAME-bake_$(ct_random_string)"
ct_s2i_build_as_df "file://$test_dir/examples/s2i-dump-data" "${IMAGE_NAME}" "$s2i_image_name" 1>/dev/null
images_to_clean+=( "$s2i_image_name" )

local container_name=bake-data-test

DOCKER_ARGS="-e POSTGRESQL_ADMIN_PASSWORD=password" \
IMAGE_NAME="$s2i_image_name" create_container "$container_name"

wait_ready "$container_name" || \
false "FAIL: Container did not start up properly."

test "hello world" == "$(docker exec "$(get_cid "$container_name")" \
bash -c "psql -tA -c 'SELECT * FROM test;'")"
}

# run_s2i_enable_ssl_test
# --------------------
# Creates S2I image with SSL config and certificates. Tries to connect with
Expand All @@ -957,26 +905,78 @@ run_s2i_enable_ssl_test()
false "FAIL: Did not manage to connect using SSL only."
}

# run_s2i_bake_data_test
# run_upgrade_test
# --------------------
# Testing pre-start script and `init.sql` file with prefilled data placed in S2I
# resulting image.
run_s2i_bake_data_test ()
# Testing upgrade from previous version to current version using
# POSTGRESQL_UPGRADE env variable. Checks that upgrade is successfull using two
# demo databases (simple and pagila)
run_upgrade_test ()
{
local s2i_image_name="$IMAGE_NAME-bake_$(ct_random_string)"
ct_s2i_build_as_df "file://$test_dir/examples/s2i-dump-data" "${IMAGE_NAME}" "$s2i_image_name" 1>/dev/null
images_to_clean+=( "$s2i_image_name" )
local ret=0

local container_name=bake-data-test
local upgrade_path= prev= act=
case $OS in
rhel8)
upgrade_path="none 12 13 15 16 none"
;;
rhel9|c9s)
upgrade_path="none 13 15 16 none"
;;
rhel10|c10s)
upgrade_path="none 13 15 16 none"
;;
fedora)
upgrade_path="none 12 13 14 15 16 none"
;;
*)
echo "unsupported OS variable" >&2
return 1
;;
esac

DOCKER_ARGS="-e POSTGRESQL_ADMIN_PASSWORD=password" \
IMAGE_NAME="$s2i_image_name" create_container "$container_name"
for act in $upgrade_path; do
if test "$act" = $VERSION; then
break
fi
prev=$act
done
test "$prev" != none || return 0
# Check if the previous image is available in the registry
docker pull "$(get_image_id "$prev:remote")" || return 0

wait_ready "$container_name" || \
false "FAIL: Container did not start up properly."
# TODO: We run this script from $VERSION directory, through test/run symlink.
test/run_upgrade_test "$prev:remote" "$VERSION:local" || ret=1
if [ $ret -eq 0 ]; then
echo " Success!"
fi
return $ret
}

test "hello world" == "$(docker exec "$(get_cid "$container_name")" \
bash -c "psql -tA -c 'SELECT * FROM test;'")"
# run_migration_test
# --------------------
# Testing migration from each supported version to currently tested one. Pagila
# is used as a demo database - data integrity is checked. Asserts that no
# invalid options can be passed without container failing to start.
run_migration_test ()
{
local ret=0
[ "${OS}" == "fedora" ] && return 0

local from_version
local upgrade_path="12 13 15 16"

for from_version in $upgrade_path; do
# Do not test migration from $VERSION:remote to $VERSION:local
test $(version2number $from_version) -lt $(version2number "$VERSION") \
|| break
# Skip if the previous image is not available in the registry
docker pull "$(get_image_id "$from_version:remote")" || continue
test/run_migration_test $from_version:remote $VERSION:local || ret=1
done
if [ $ret -eq 0 ]; then
echo " Success!"
fi
return $ret
}

# run_pgaudit_test
Expand Down Expand Up @@ -1043,6 +1043,17 @@ EOSQL" || ret=3
return $ret
}

# run_env_extension_load_test
# --------------------
# Tries to load pgaudit extension using environment variables
# `POSTGRESQL_EXTENSIONS` and `POSTGRESQL_LIBRARIES`
run_env_extension_load_test() {
DOCKER_EXTRA_ARGS="
-e POSTGRESQL_EXTENSIONS=pgaudit
-e POSTGRESQL_LIBRARIES=pgaudit"
run_pgaudit_test
}

# run_logging_test
# --------------------
# Checks that changing log location via `POSTGRESQL_LOG_DESTINATION` env
Expand Down Expand Up @@ -1090,17 +1101,6 @@ run_logging_test()
echo " Success!"
}

# run_env_extension_load_test
# --------------------
# Tries to load pgaudit extension using environment variables
# `POSTGRESQL_EXTENSIONS` and `POSTGRESQL_LIBRARIES`
run_env_extension_load_test() {
DOCKER_EXTRA_ARGS="
-e POSTGRESQL_EXTENSIONS=pgaudit
-e POSTGRESQL_LIBRARIES=pgaudit"
run_pgaudit_test
}

# configuration defaults
POSTGRESQL_MAX_CONNECTIONS=100
POSTGRESQL_MAX_PREPARED_TRANSACTIONS=0
Expand Down

0 comments on commit f4d56eb

Please sign in to comment.