#!/bin/bash
#
# Test the Ruby S2I 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 Ruby runtime in format of X.Y
# OS specifies RHEL version (e.g. OS=rhel7)
#

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

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

set -eo nounset

trap ct_os_cleanup EXIT SIGINT

ct_os_check_compulsory_vars

ct_os_enable_print_logs

ct_os_cluster_up

# test with the just built image and an integrated template
test_ruby_integration "${IMAGE_NAME}"

# Check the imagestream
test_ruby_imagestream

# test with a released image and an integrated template
PUBLIC_IMAGE_NAME=${PUBLIC_IMAGE_NAME:-$(ct_get_public_image_name "${OS}" "${BASE_IMAGE_NAME}" "${VERSION}")}

# Try pulling the image first to see if it is accessible
if docker pull "${PUBLIC_IMAGE_NAME}"; then
  export CT_SKIP_UPLOAD_IMAGE=true
  test_ruby_integration "${PUBLIC_IMAGE_NAME}"
else
  echo "Warning: ${PUBLIC_IMAGE_NAME} could not be downloaded via 'docker'"
  # ignore possible failure of this test for centos images
  [ "${OS}" == "rhel7" ] && false "ERROR: Failed to pull image"
fi

OS_TESTSUITE_RESULT=0

ct_os_cluster_down

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

