#!/bin/bash
#
# Test the Python image in the OpenShift.
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# VERSION specifies a version of the python in the candidate image.
# The image has to be available before this script is executed.

THISDIR=$(dirname ${BASH_SOURCE[0]})
test_dir="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"

source "${THISDIR}/test-lib.sh"
source "${THISDIR}/test-lib-openshift.sh"
source "${THISDIR}/test-lib-python.sh"

set -eo nounset

trap ct_os_cleanup EXIT SIGINT

test_latest_imagestreams() {
  info "Testing the latest version in imagestreams"
  # Switch to root directory of a container
  pushd "${test_dir}/../.." >/dev/null
  ct_check_latest_imagestreams
  popd >/dev/null
}

ct_os_check_compulsory_vars

ct_os_enable_print_logs

if [ -z "${EPHEMERAL_TEMPLATES:-}" ]; then
    EPHEMERAL_TEMPLATES="
https://raw.githubusercontent.com/sclorg/django-ex/master/openshift/templates/django-postgresql.json \
https://raw.githubusercontent.com/openshift/origin/master/examples/quickstarts/django-postgresql.json"
fi

ct_os_cluster_up

ct_os_test_s2i_app "${IMAGE_NAME}" "${THISDIR}/standalone-test-app" . "Hello World from standalone WSGI application!"

ct_os_test_s2i_app "${IMAGE_NAME}" "https://github.com/sclorg/django-ex.git" . 'Welcome to your Django application on OpenShift'

for template in $EPHEMERAL_TEMPLATES; do
    ct_os_test_template_app "$IMAGE_NAME" \
                            "$template" \
                            python \
                            'Welcome to your Django application on OpenShift' \
                            8080 http 200 "-p SOURCE_REPOSITORY_REF=master -p PYTHON_VERSION=${VERSION} -p POSTGRESQL_VERSION=10 -p NAME=python-testing" \
                            "quay.io/centos7/postgresql-10-centos7|postgresql:10"
done

# Check the imagestream
test_python_imagestream

# check if latest imagestream version is correct
test_latest_imagestreams

OS_TESTSUITE_RESULT=0

ct_os_cluster_down

# vim: set tabstop=2:shiftwidth=2:expandtab:

