@@ -37,6 +37,10 @@ test -n "${VERSION-}" || false 'make sure $VERSION is defined'
3737test -n " ${OS-} " || false ' make sure $OS is defined'
3838
3939
40+ # ###
41+ # HELPER FUNCTIONS
42+ # ###
43+ 4044DOCKER_EXTRA_ARGS=
4145
4246volumes_to_clean=
@@ -291,35 +295,6 @@ function try_image_invalid_combinations() {
291295 return $ret
292296}
293297
294- # run_container_creation_tests
295- # --------------------
296- # Asserts that container image fails to run in certain illegal use of arguments,
297- # while it correctly runs in other combinations.
298- # NOTE: Previously the `creation_succeeds` combinations were supposed to fail, but
299- # these cases are now supposed to work
300- function run_container_creation_tests() {
301- local ret=0
302- echo " Testing image entrypoint usage"
303- try_image_invalid_combinations || ret=1
304- try_image_invalid_combinations -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=2
305- 306- VERY_LONG_IDENTIFIER=" very_long_identifier_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
307- assert_container_creation_fails -e POSTGRESQL_USER= -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=3
308- assert_container_creation_fails -e POSTGRESQL_USER=$VERY_LONG_IDENTIFIER -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=4
309- assert_container_creation_succeeds -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=" \" " -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=5
310- assert_container_creation_succeeds -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=9invalid -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=6
311- assert_container_creation_fails -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=$VERY_LONG_IDENTIFIER -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=7
312- assert_container_creation_succeeds -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD=" \" " || ret=8
313- 314- assert_container_creation_succeeds -e POSTGRESQL_ADMIN_PASSWORD=" the @password" || ret=9
315- assert_container_creation_succeeds -e POSTGRESQL_PASSWORD=" the pass" -e POSTGRESQL_USER=" the user" -e POSTGRESQL_DATABASE=" the db" || ret=10
316- 317- if [ $ret -eq 0 ]; then
318- echo " Success!"
319- fi
320- return $ret
321- }
322- 323298function test_config_option() {
324299 local name=1ドル ; shift
325300 local setting=1ドル ; shift
@@ -537,6 +512,38 @@ function setup_replication_cluster() {
537512
538513}
539514
515+ test_the_app_image () {
516+ local container_name=1ドル
517+ local mount_opts=2ドル
518+ local ret=0
519+ echo " Testing s2i app image with invalid configuration"
520+ assert_container_creation_fails -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db || ret=1
521+ echo " Testing s2i app image with correct configuration"
522+ 523+ DOCKER_ARGS="
524+ -e POSTGRESQL_DATABASE=db
525+ -e POSTGRESQL_USER=user
526+ -e POSTGRESQL_PASSWORD=password
527+ -e POSTGRESQL_ADMIN_PASSWORD=password
528+ -e POSTGRESQL_BACKUP_USER=backuser
529+ -e POSTGRESQL_BACKUP_PASSWORD=pass
530+ ${mount_opts}
531+ " create_container " $container_name " || ret=2
532+ 533+ # need this to wait for the container to start up
534+ PGUSER=user PASS=password test_connection " $container_name " || ret=3
535+ PGUSER=backuser PASS=pass DB=backup test_connection " $container_name " || ret=4
536+ if [ $ret -eq 0 ]; then
537+ echo " Success!"
538+ fi
539+ return $ret
540+ }
541+ 542+ 543+ # ###
544+ # DISABLED TESTS
545+ # ###
546+ 540547# This test is removed from the test suite
541548# In our CI is failing sporadically and solution is not available yet.
542549# Let's remove it from test but the test function remains.
@@ -589,6 +596,68 @@ function run_master_restart_test() {
589596 return $ret
590597}
591598
599+ # run_doc_test
600+ # --------------------
601+ # Checks whether `help.1` file with specific terms is included in default
602+ # working directory in the container image.
603+ run_doc_test () {
604+ local tmpdir=$( mktemp -d)
605+ local f
606+ echo " Testing documentation in the container image"
607+ # Extract the help files from the container
608+ for f in help.1 ; do
609+ docker run --rm ${IMAGE_NAME} /bin/bash -c " cat /${f} " > ${tmpdir} /$( basename ${f} )
610+ # Check whether the files include some important information
611+ for term in ' POSTGRESQL\\?_ADMIN\\?_PASSWORD' Volume 5432 ; do
612+ if ! cat ${tmpdir} /$( basename ${f} ) | grep -E -q -e " ${term} " ; then
613+ echo " ERROR: File /${f} does not include '${term} '."
614+ return 1
615+ fi
616+ done
617+ done
618+ # Check whether the files use the correct format
619+ if ! file ${tmpdir} /help.1 | grep -q roff ; then
620+ echo " ERROR: /help.1 is not in troff or groff format"
621+ return 1
622+ fi
623+ echo " Success!"
624+ echo
625+ }
626+ 627+ 628+ # ###
629+ # TESTING FUNCTIONS
630+ # ###
631+ 632+ # run_container_creation_tests
633+ # --------------------
634+ # Asserts that container image fails to run in certain illegal use of arguments,
635+ # while it correctly runs in other combinations.
636+ # NOTE: Previously the `creation_succeeds` combinations were supposed to fail, but
637+ # these cases are now supposed to work
638+ function run_container_creation_tests() {
639+ local ret=0
640+ echo " Testing image entrypoint usage"
641+ try_image_invalid_combinations || ret=1
642+ try_image_invalid_combinations -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=2
643+ 644+ VERY_LONG_IDENTIFIER=" very_long_identifier_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
645+ assert_container_creation_fails -e POSTGRESQL_USER= -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=3
646+ assert_container_creation_fails -e POSTGRESQL_USER=$VERY_LONG_IDENTIFIER -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=4
647+ assert_container_creation_succeeds -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=" \" " -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=5
648+ assert_container_creation_succeeds -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=9invalid -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=6
649+ assert_container_creation_fails -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=$VERY_LONG_IDENTIFIER -e POSTGRESQL_ADMIN_PASSWORD=admin_pass || ret=7
650+ assert_container_creation_succeeds -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD=" \" " || ret=8
651+ 652+ assert_container_creation_succeeds -e POSTGRESQL_ADMIN_PASSWORD=" the @password" || ret=9
653+ assert_container_creation_succeeds -e POSTGRESQL_PASSWORD=" the pass" -e POSTGRESQL_USER=" the user" -e POSTGRESQL_DATABASE=" the db" || ret=10
654+ 655+ if [ $ret -eq 0 ]; then
656+ echo " Success!"
657+ fi
658+ return $ret
659+ }
660+ 592661# run_replication_test
593662# --------------------
594663# Start two containers one as main, one as secondary. Checks whether the main
@@ -775,61 +844,6 @@ run_migration_test ()
775844 return $ret
776845}
777846
778- # run_doc_test
779- # --------------------
780- # Checks whether `help.1` file with specific terms is included in default
781- # working directory in the container image.
782- run_doc_test () {
783- local tmpdir=$( mktemp -d)
784- local f
785- echo " Testing documentation in the container image"
786- # Extract the help files from the container
787- for f in help.1 ; do
788- docker run --rm ${IMAGE_NAME} /bin/bash -c " cat /${f} " > ${tmpdir} /$( basename ${f} )
789- # Check whether the files include some important information
790- for term in ' POSTGRESQL\\?_ADMIN\\?_PASSWORD' Volume 5432 ; do
791- if ! cat ${tmpdir} /$( basename ${f} ) | grep -E -q -e " ${term} " ; then
792- echo " ERROR: File /${f} does not include '${term} '."
793- return 1
794- fi
795- done
796- done
797- # Check whether the files use the correct format
798- if ! file ${tmpdir} /help.1 | grep -q roff ; then
799- echo " ERROR: /help.1 is not in troff or groff format"
800- return 1
801- fi
802- echo " Success!"
803- echo
804- }
805- 806- test_the_app_image () {
807- local container_name=1ドル
808- local mount_opts=2ドル
809- local ret=0
810- echo " Testing s2i app image with invalid configuration"
811- assert_container_creation_fails -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db || ret=1
812- echo " Testing s2i app image with correct configuration"
813- 814- DOCKER_ARGS="
815- -e POSTGRESQL_DATABASE=db
816- -e POSTGRESQL_USER=user
817- -e POSTGRESQL_PASSWORD=password
818- -e POSTGRESQL_ADMIN_PASSWORD=password
819- -e POSTGRESQL_BACKUP_USER=backuser
820- -e POSTGRESQL_BACKUP_PASSWORD=pass
821- ${mount_opts}
822- " create_container " $container_name " || ret=2
823- 824- # need this to wait for the container to start up
825- PGUSER=user PASS=password test_connection " $container_name " || ret=3
826- PGUSER=backuser PASS=pass DB=backup test_connection " $container_name " || ret=4
827- if [ $ret -eq 0 ]; then
828- echo " Success!"
829- fi
830- return $ret
831- }
832- 833847# run_s2i_test
834848# --------------------
835849# Build S2I image with basic script. Try running the container with usage of the
0 commit comments