#!/bin/bash # # The 'run' performs a simple test that verifies that STI image. # The main focus here is to exercise the STI scripts. # # IMAGE_NAME specifies a name of the candidate image used for testing. # The image has to be available before this script is executed. # # For each client package test, XXX_REVISION specifies which # branch or tag should be tested; by default it uses the latest # released version as reported by `npm show XXX version` where # XXX is the name of the npm package. # # For each client package XXX_REPO must be defined in this # test file to set the repository that corresponds to the # npm package XXX. THISDIR=$(dirname ${BASH_SOURCE[0]}) TEST_LIST_APP="\ test_run_app_application test_s2i_usage test_scl_usage test_connection test_docker_run_usage test_scl_variables_in_dockerfile test_npm_functionality test_check_build_using_dockerfile test_nodemon_removed test_npm_cache_cleared test_npm_tmp_cleared kill_test_application test_dev_mode_true_development test_dev_mode_false_production " TEST_LIST_BINARY="\ test_run_binary_application " TEST_LIST_NODE_ENV="\ test_run_app_application test_connection test_nodemon_present test_npm_cache_exists kill_test_application test_dev_mode_true_development test_dev_mode_false_development " TEST_LIST_DEV_MODE="\ test_run_app_application test_connection test_nodemon_present test_npm_cache_exists kill_test_application test_dev_mode_true_development test_dev_mode_false_production " TEST_LIST_HW="\ test_safe_logging test_run_hw_application test_incremental_build test_build_express_webapp " # define the client npm packages to be tested. For # each entry XXX in the list a corresponding value for # XXX_REVISION and XXX_REPO must be defined below TEST_LIST_CLIENTS="\ express pino prom-client opossum kube-service-bindings " CLIENT_LIST=($TEST_LIST_CLIENTS) readonly EXPRESS_REVISION="${EXPRESS_REVISION:-$(docker run --rm "${IMAGE_NAME}" -- npm show express version)}" readonly EXPRESS_REPO="https://github.com/expressjs/express.git" readonly PINO_REVISION=v"${PINO_REVISION:-$(docker run --rm "${IMAGE_NAME}" -- npm show pino version)}" readonly PINO_REPO="https://github.com/pinojs/pino.git" readonly PROMCLIENT_REVISION=v"${PROMCLIENT_REVISION:-$(docker run --rm "${IMAGE_NAME}" -- npm show prom-client version)}" readonly PROMCLIENT_REPO="https://github.com/siimon/prom-client.git" readonly OPOSSUM_REVISION="v${OPOSSUM_REVISION:-$(docker run --rm "${IMAGE_NAME}" -- npm show opossum version)}" readonly OPOSSUM_REPO="https://github.com/nodeshift/opossum.git" readonly KUBESERVICEBINDINGS_REVISION="v${KUBESERVICEBINDINGS_REVISION:-$(docker run --rm "${IMAGE_NAME}" -- npm show kube-service-bindings version)}" readonly KUBESERVICEBINDINGS_REPO="https://github.com/nodeshift/kube-service-bindings.git" source "${THISDIR}/test-lib.sh" source "${THISDIR}/test-lib-nodejs.sh" test -n $IMAGE_NAME \ -a -n $VERSION test_dir="$(readlink -f $(dirname ${BASH_SOURCE[0]}))" image_dir="$(readlink -f ${test_dir}/..)" test_short_summary='' TESTSUITE_RESULT=0 cid_file=$(mktemp -u --suffix=.cid) # Since we built the candidate image locally, we don't want S2I attempt to pull # it from Docker hub s2i_args="--pull-policy=never " # TODO: This should be part of the image metadata test_port=8080 # Common git configuration readonly -A gitconfig=( [user.name]="builder" [user.email]="build@localhost" [commit.gpgsign]="false" ) if [ "$DEBUG" != "" ]; then set -x fi # Build the application image twice to ensure the 'save-artifacts' and # 'restore-artifacts' scripts are working properly prepare app echo "Testing the production image build" run_s2i_build check_result $? TEST_SET=${TESTS:-$TEST_LIST_APP} run_all_tests "app" echo "Testing the development image build: s2i build -e \"NODE_ENV=development\")" run_s2i_build "-e NODE_ENV=development" check_result $? TEST_SET=${TESTS:-$TEST_LIST_NODE_ENV} run_all_tests "node_env_development" echo "Testing the development image build: s2i build -e \"DEV_MODE=true\")" run_s2i_build "-e DEV_MODE=true" check_result $? TEST_SET=${TESTS:-$TEST_LIST_DEV_MODE} run_all_tests "dev_mode" echo "Testing proxy safe logging..." prepare hw run_s2i_build_proxy http://user.password@0.0.0.0:8000 https://user.password@0.0.0.0:8000 > /tmp/build-log 2>&1 check_result $? TEST_SET=${TESTS:-$TEST_LIST_HW} run_all_tests "hw" check_result $? TEST_SET=${TESTS:-$TEST_LIST_CLIENTS} run_all_tests "clients" TEST_SET=${TESTS:-$TEST_LIST_BINARY} run_all_tests "binary" echo "Success!" cleanup