#!/bin/bash
#
# Test the MariaDB image in OpenShift (local cluster)
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
# VERSION specifies the major version of the MariaDB in format of X.Y
# OS specifies RHEL version (e.g. OS=rhel7)
#

THISDIR=$(dirname ${BASH_SOURCE[0]})

source ${THISDIR}/test-lib-mysql.sh

set -eo nounset

trap ct_os_cleanup EXIT SIGINT

ct_os_check_compulsory_vars

ct_os_cluster_up

test_mysql_pure_image "${IMAGE_NAME}"

test_mysql_template "${IMAGE_NAME}"

# TODO: Can we make the build against examples inside the same PR?
test_mysql_s2i "${IMAGE_NAME}" "https://github.com/sclorg/mariadb-container.git" test/test-app

# test with a current image and integrated template
export CT_NAMESPACE=openshift
test_mariadb_integration "${IMAGE_NAME}" "${VERSION}"

# test with a released image and integrated template
export CT_SKIP_UPLOAD_IMAGE=true
case ${OS} in
  rhel7) IMAGE_NAME=rhscl/mariadb-${VERSION//./}-rhel7 ;;
  *) ;;
esac
test_mariadb_integration mariadb "${VERSION}" "registry.access.redhat.com/${IMAGE_NAME}"

OS_TESTSUITE_RESULT=0

