@@ -658,32 +658,19 @@ VERY_LONG_IDENTIFIER="very_long_identifier_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
658
658
return $ret
659
659
}
660
660
661
- # run_replication_test
661
+ # run_general_tests
662
662
# --------------------
663
- # Start two containers one as main, one as secondary. Checks whether the main
664
- # sees secondary server connected. Tries to create data on main server and
665
- # checks whether they are correctly replicated to secondary server.
666
- function run_replication_test() {
667
- local DB=postgres
668
- local PGUSER=master
669
- local PASS=master
663
+ # Tests different combinations of parameters and that they work. Also tests SCL
664
+ # usage. Tries to actually SELECT something from the database.
665
+ function run_general_tests() {
670
666
local ret=0
671
-
672
- echo " Testing master-slave replication"
673
- local cluster_args=" -e POSTGRESQL_ADMIN_PASSWORD=pass -e POSTGRESQL_MASTER_USER=$PGUSER -e POSTGRESQL_MASTER_PASSWORD=$PASS "
674
- local cid_suffix=" basic"
675
- local master_ip=
676
- local slave_cids=
677
-
678
- # Setup the cluster
679
- setup_replication_cluster || ret=1
680
-
681
- # Check if the master knows about the slaves
682
- CONTAINER_IP=$master_ip
683
- test_slave_visibility || ret=2
684
-
685
- # Do some real work to test replication in practice
686
- table_name=" t1" test_value_replication || ret=3
667
+ PGUSER=user PASS=pass POSTGRESQL_MAX_CONNECTIONS=42 POSTGRESQL_MAX_PREPARED_TRANSACTIONS=42 POSTGRESQL_SHARED_BUFFERS=64MB run_tests no_admin || ret=1
668
+ PGUSER=user1 PASS=pass1 ADMIN_PASS=r00t run_tests admin || ret=2
669
+ DB=postgres ADMIN_PASS=r00t run_tests only_admin || ret=3
670
+ # Test with arbitrary uid for the container
671
+ DOCKER_ARGS=" -u 12345" PGUSER=user2 PASS=pass run_tests no_admin_altuid || ret=4
672
+ DOCKER_ARGS=" -u 12345" PGUSER=user3 PASS=pass1 ADMIN_PASS=r00t run_tests admin_altuid || ret=5
673
+ DB=postgres DOCKER_ARGS=" -u 12345" ADMIN_PASS=rOOt run_tests only_admin_altuid || ret=6
687
674
if [ $ret -eq 0 ]; then
688
675
echo " Success!"
689
676
fi
@@ -770,74 +757,32 @@ $volume_options
770
757
return $ret
771
758
}
772
759
773
- # run_upgrade_test
760
+ # run_replication_test
774
761
# --------------------
775
- # Testing upgrade from previous version to current version using
776
- # POSTGRESQL_UPGRADE env variable. Checks that upgrade is successfull using two
777
- # demo databases (simple and pagila)
778
- run_upgrade_test ()
779
- {
762
+ # Start two containers one as main, one as secondary. Checks whether the main
763
+ # sees secondary server connected. Tries to create data on main server and
764
+ # checks whether they are correctly replicated to secondary server.
765
+ function run_replication_test() {
766
+ local DB=postgres
767
+ local PGUSER=master
768
+ local PASS=master
780
769
local ret=0
781
770
782
- local upgrade_path= prev= act=
783
- case $OS in
784
- rhel8)
785
- upgrade_path=" none 12 13 15 16 none"
786
- ;;
787
- rhel9|c9s)
788
- upgrade_path=" none 13 15 16 none"
789
- ;;
790
- rhel10|c10s)
791
- upgrade_path=" none 13 15 16 none"
792
- ;;
793
- fedora)
794
- upgrade_path=" none 12 13 14 15 16 none"
795
- ;;
796
- * )
797
- echo " unsupported OS variable" >&2
798
- return 1
799
- ;;
800
- esac
801
-
802
- for act in $upgrade_path ; do
803
- if test " $act " = $VERSION ; then
804
- break
805
- fi
806
- prev=$act
807
- done
808
- test " $prev " ! = none || return 0
809
- # Check if the previous image is available in the registry
810
- docker pull " $( get_image_id " $prev :remote" ) " || return 0
811
-
812
- # TODO: We run this script from $VERSION directory, through test/run symlink.
813
- test/run_upgrade_test " $prev :remote" " $VERSION :local" || ret=1
814
- if [ $ret -eq 0 ]; then
815
- echo " Success!"
816
- fi
817
- return $ret
818
- }
771
+ echo " Testing master-slave replication"
772
+ local cluster_args=" -e POSTGRESQL_ADMIN_PASSWORD=pass -e POSTGRESQL_MASTER_USER=$PGUSER -e POSTGRESQL_MASTER_PASSWORD=$PASS "
773
+ local cid_suffix=" basic"
774
+ local master_ip=
775
+ local slave_cids=
819
776
820
- # run_migration_test
821
- # --------------------
822
- # Testing migration from each supported version to currently tested one. Pagila
823
- # is used as a demo database - data integrity is checked. Asserts that no
824
- # invalid options can be passed without container failing to start.
825
- run_migration_test ()
826
- {
827
- local ret=0
828
- [ " ${OS} " == " fedora" ] && return 0
777
+ # Setup the cluster
778
+ setup_replication_cluster || ret=1
829
779
830
- local from_version
831
- local upgrade_path=" 12 13 15 16"
780
+ # Check if the master knows about the slaves
781
+ CONTAINER_IP=$master_ip
782
+ test_slave_visibility || ret=2
832
783
833
- for from_version in $upgrade_path ; do
834
- # Do not test migration from $VERSION:remote to $VERSION:local
835
- test $( version2number $from_version ) -lt $( version2number " $VERSION " ) \
836
- || break
837
- # Skip if the previous image is not available in the registry
838
- docker pull " $( get_image_id " $from_version :remote" ) " || continue
839
- test/run_migration_test $from_version :remote $VERSION :local || ret=1
840
- done
784
+ # Do some real work to test replication in practice
785
+ table_name=" t1" test_value_replication || ret=3
841
786
if [ $ret -eq 0 ]; then
842
787
echo " Success!"
843
788
fi
@@ -873,25 +818,6 @@ run_s2i_test() {
873
818
return $ret
874
819
}
875
820
876
- # run_general_tests
877
- # --------------------
878
- # Tests different combinations of parameters and that they work. Also tests SCL
879
- # usage. Tries to actually SELECT something from the database.
880
- function run_general_tests() {
881
- local ret=0
882
- PGUSER=user PASS=pass POSTGRESQL_MAX_CONNECTIONS=42 POSTGRESQL_MAX_PREPARED_TRANSACTIONS=42 POSTGRESQL_SHARED_BUFFERS=64MB run_tests no_admin || ret=1
883
- PGUSER=user1 PASS=pass1 ADMIN_PASS=r00t run_tests admin || ret=2
884
- DB=postgres ADMIN_PASS=r00t run_tests only_admin || ret=3
885
- # Test with arbitrary uid for the container
886
- DOCKER_ARGS=" -u 12345" PGUSER=user2 PASS=pass run_tests no_admin_altuid || ret=4
887
- DOCKER_ARGS=" -u 12345" PGUSER=user3 PASS=pass1 ADMIN_PASS=r00t run_tests admin_altuid || ret=5
888
- DB=postgres DOCKER_ARGS=" -u 12345" ADMIN_PASS=rOOt run_tests only_admin_altuid || ret=6
889
- if [ $ret -eq 0 ]; then
890
- echo " Success!"
891
- fi
892
- return $ret
893
- }
894
-
895
821
# run_test_cfg_hook
896
822
# --------------------
897
823
# Checks whether using config files in persistent mounted volume works. Also
@@ -932,6 +858,28 @@ run_test_cfg_hook()
932
858
return $ret
933
859
}
934
860
861
+ # run_s2i_bake_data_test
862
+ # --------------------
863
+ # Testing pre-start script and `init.sql` file with prefilled data placed in S2I
864
+ # resulting image.
865
+ run_s2i_bake_data_test ()
866
+ {
867
+ local s2i_image_name=" $IMAGE_NAME -bake_$( ct_random_string) "
868
+ ct_s2i_build_as_df " file://$test_dir /examples/s2i-dump-data" " ${IMAGE_NAME} " " $s2i_image_name " 1> /dev/null
869
+ images_to_clean+=( " $s2i_image_name " )
870
+
871
+ local container_name=bake-data-test
872
+
873
+ DOCKER_ARGS=" -e POSTGRESQL_ADMIN_PASSWORD=password" \
874
+ IMAGE_NAME=" $s2i_image_name " create_container " $container_name "
875
+
876
+ wait_ready " $container_name " || \
877
+ false " FAIL: Container did not start up properly."
878
+
879
+ test " hello world" == " $( docker exec " $( get_cid " $container_name " ) " \
880
+ bash -c " psql -tA -c 'SELECT * FROM test;'" ) "
881
+ }
882
+
935
883
# run_s2i_enable_ssl_test
936
884
# --------------------
937
885
# Creates S2I image with SSL config and certificates. Tries to connect with
@@ -957,26 +905,78 @@ run_s2i_enable_ssl_test()
957
905
false " FAIL: Did not manage to connect using SSL only."
958
906
}
959
907
960
- # run_s2i_bake_data_test
908
+ # run_upgrade_test
961
909
# --------------------
962
- # Testing pre-start script and `init.sql` file with prefilled data placed in S2I
963
- # resulting image.
964
- run_s2i_bake_data_test ()
910
+ # Testing upgrade from previous version to current version using
911
+ # POSTGRESQL_UPGRADE env variable. Checks that upgrade is successfull using two
912
+ # demo databases (simple and pagila)
913
+ run_upgrade_test ()
965
914
{
966
- local s2i_image_name=" $IMAGE_NAME -bake_$( ct_random_string) "
967
- ct_s2i_build_as_df " file://$test_dir /examples/s2i-dump-data" " ${IMAGE_NAME} " " $s2i_image_name " 1> /dev/null
968
- images_to_clean+=( " $s2i_image_name " )
915
+ local ret=0
969
916
970
- local container_name=bake-data-test
917
+ local upgrade_path= prev= act=
918
+ case $OS in
919
+ rhel8)
920
+ upgrade_path=" none 12 13 15 16 none"
921
+ ;;
922
+ rhel9|c9s)
923
+ upgrade_path=" none 13 15 16 none"
924
+ ;;
925
+ rhel10|c10s)
926
+ upgrade_path=" none 13 15 16 none"
927
+ ;;
928
+ fedora)
929
+ upgrade_path=" none 12 13 14 15 16 none"
930
+ ;;
931
+ * )
932
+ echo " unsupported OS variable" >&2
933
+ return 1
934
+ ;;
935
+ esac
971
936
972
- DOCKER_ARGS=" -e POSTGRESQL_ADMIN_PASSWORD=password" \
973
- IMAGE_NAME=" $s2i_image_name " create_container " $container_name "
937
+ for act in $upgrade_path ; do
938
+ if test " $act " = $VERSION ; then
939
+ break
940
+ fi
941
+ prev=$act
942
+ done
943
+ test " $prev " ! = none || return 0
944
+ # Check if the previous image is available in the registry
945
+ docker pull " $( get_image_id " $prev :remote" ) " || return 0
974
946
975
- wait_ready " $container_name " || \
976
- false " FAIL: Container did not start up properly."
947
+ # TODO: We run this script from $VERSION directory, through test/run symlink.
948
+ test/run_upgrade_test " $prev :remote" " $VERSION :local" || ret=1
949
+ if [ $ret -eq 0 ]; then
950
+ echo " Success!"
951
+ fi
952
+ return $ret
953
+ }
977
954
978
- test " hello world" == " $( docker exec " $( get_cid " $container_name " ) " \
979
- bash -c " psql -tA -c 'SELECT * FROM test;'" ) "
955
+ # run_migration_test
956
+ # --------------------
957
+ # Testing migration from each supported version to currently tested one. Pagila
958
+ # is used as a demo database - data integrity is checked. Asserts that no
959
+ # invalid options can be passed without container failing to start.
960
+ run_migration_test ()
961
+ {
962
+ local ret=0
963
+ [ " ${OS} " == " fedora" ] && return 0
964
+
965
+ local from_version
966
+ local upgrade_path=" 12 13 15 16"
967
+
968
+ for from_version in $upgrade_path ; do
969
+ # Do not test migration from $VERSION:remote to $VERSION:local
970
+ test $( version2number $from_version ) -lt $( version2number " $VERSION " ) \
971
+ || break
972
+ # Skip if the previous image is not available in the registry
973
+ docker pull " $( get_image_id " $from_version :remote" ) " || continue
974
+ test/run_migration_test $from_version :remote $VERSION :local || ret=1
975
+ done
976
+ if [ $ret -eq 0 ]; then
977
+ echo " Success!"
978
+ fi
979
+ return $ret
980
980
}
981
981
982
982
# run_pgaudit_test
@@ -1043,6 +1043,17 @@ EOSQL" || ret=3
1043
1043
return $ret
1044
1044
}
1045
1045
1046
+ # run_env_extension_load_test
1047
+ # --------------------
1048
+ # Tries to load pgaudit extension using environment variables
1049
+ # `POSTGRESQL_EXTENSIONS` and `POSTGRESQL_LIBRARIES`
1050
+ run_env_extension_load_test () {
1051
+ DOCKER_EXTRA_ARGS="
1052
+ -e POSTGRESQL_EXTENSIONS=pgaudit
1053
+ -e POSTGRESQL_LIBRARIES=pgaudit"
1054
+ run_pgaudit_test
1055
+ }
1056
+
1046
1057
# run_logging_test
1047
1058
# --------------------
1048
1059
# Checks that changing log location via `POSTGRESQL_LOG_DESTINATION` env
@@ -1090,17 +1101,6 @@ run_logging_test()
1090
1101
echo " Success!"
1091
1102
}
1092
1103
1093
- # run_env_extension_load_test
1094
- # --------------------
1095
- # Tries to load pgaudit extension using environment variables
1096
- # `POSTGRESQL_EXTENSIONS` and `POSTGRESQL_LIBRARIES`
1097
- run_env_extension_load_test () {
1098
- DOCKER_EXTRA_ARGS="
1099
- -e POSTGRESQL_EXTENSIONS=pgaudit
1100
- -e POSTGRESQL_LIBRARIES=pgaudit"
1101
- run_pgaudit_test
1102
- }
1103
-
1104
1104
# configuration defaults
1105
1105
POSTGRESQL_MAX_CONNECTIONS=100
1106
1106
POSTGRESQL_MAX_PREPARED_TRANSACTIONS=0
0 commit comments