#!/bin/bash
#
# The 'run' performs a simple test that verifies that STI image.
# The main focus is that the image prints out the base-usage properly.
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
#
test -n "${IMAGE_NAME-}" || { echo 'make sure $IMAGE_NAME is defined'; exit 1; }

test_docker_run_usage() {
	echo "Testing 'docker run' usage..."
	docker run --rm ${IMAGE_NAME} &>/dev/null
}

check_result() {
	local result="$1"
	if [[ "$result" != "0" ]]; then
		echo "STI image '${IMAGE_NAME}' test FAILED (exit code: ${result})"
		exit $result
	fi
}

# Verify the 'usage' script is working properly when running the base image with 'docker run ...'
test_docker_run_usage
check_result $?
