#!/usr/bin/env bash

set -e

if ! which pytest &>/dev/null; then
  echo "pytest is required (install with pip(3) install pytest)"
  exit 1
fi

# usage: $1: <src-dir>

src_dir="${1:-"$(readlink -f "$(dirname "${0}")/..")"}"

export PYTHONPATH="${src_dir}:${src_dir}/cli/gardener_ci:${PYTHONPATH:-}"

if python3 -m pytest "${src_dir}" "${@}"; then
    echo 'Unittest executions succeeded'
    exit 0
else
    echo 'Errors were found whilst executing unittests (see above)'
    exit 1
fi
