From f4d56eb401bb68776a40ec765617b575525f43c1 Mon Sep 17 00:00:00 2001 From: Ales Nezbeda Date: Fri, 1 Nov 2024 15:35:00 +0100 Subject: [PATCH] Reorder tests sources to match order of tests in TEST_LIST --- test/run_test | 260 +++++++++++++++++++++++++------------------------- 1 file changed, 130 insertions(+), 130 deletions(-) diff --git a/test/run_test b/test/run_test index d459369e..98e9fdb2 100755 --- a/test/run_test +++ b/test/run_test @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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