#!/bin/sh

set -e

# A missing oci-poc-local.conf must be fatal: the user-owned values
# are defined nowhere else, so the script cannot work without it.
. ./lib.sh
SANDBOX=$(mktemp -d)
trap 'rm -rf ${SANDBOX}' EXIT
SCRIPT=$(setup_sandbox utils/usr/bin/oci-poc-provision-octavia-image "${SANDBOX}")
rm -f "${SANDBOX}/etc/oci-poc/oci-poc-local.conf"

if PATH="${SANDBOX}/bin:$PATH" sh "${SCRIPT}" >"${SANDBOX}/out.txt" 2>"${SANDBOX}/err.txt" ; then
	echo "octavia-image succeeded without the mandatory -local conf"
	cat "${SANDBOX}/out.txt" "${SANDBOX}/err.txt"
	exit 1
fi

if ! grep -q "Cannot read .*oci-poc-local.conf: exiting." "${SANDBOX}/out.txt" "${SANDBOX}/err.txt" ; then
	echo "the failure doesn't mention the missing -local conf"
	cat "${SANDBOX}/out.txt" "${SANDBOX}/err.txt"
	exit 1
fi
exit 0
