You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
system-tests/ngcp-system-tests

111 lines
2.1 KiB

#!/bin/bash
set -e
set -E
declare -r ME="$(basename "$0")"
declare -r OPTS=("$@")
declare -a PROVE_OPTS=()
NGCP_TESTS_MODE=${NGCP_TESTS_MODE:=prove}
error() {
if [ "${NGCP_TESTS_MODE}" = 'tap' ]; then
echo "Bail out! $*" >&2
else
echo "$ME: error: $*" >&2
fi
exit 1
}
usage() {
cat <<HELP
Usage: ${ME} [<option>...]
Options:
--mode <name> Operation mode to use. Values: jenkins, tap, prove.
-h, --help Print this help message and exit.
HELP
}
get_options() {
local _cmdline_opts="help,mode:"
local _opt_temp
_opt_temp=$(getopt -n "${ME}" -o 'h' -l "${_cmdline_opts}" -- "${OPTS[@]}")
eval set -- "${_opt_temp}"
while :; do
case "$1" in
--help|-h)
usage
exit 0
;;
--mode)
shift
NGCP_TESTS_MODE="$1"
;;
--)
shift
break
;;
*)
error "Internal getopt error! $1"
;;
esac
shift
done
PROVE_OPTS=("$@")
}
if ! [ -d /etc/ngcp-system-tests/ ]; then
error "Missing system test suite files, please run 'ngcpcfg build'"
fi
get_options "$@"
case "${NGCP_TESTS_MODE}" in
jenkins)
export GOSS_NOCOLOR=true
$0 --mode=tap
;;
prove)
export NGCP_TESTS_MODE=tap
prove "${PROVE_OPTS[@]}" -f "$0"
;;
*)
DEBIAN_RELEASE=$(sed -e 's/\([0-9]*\)\..*/\1/' /etc/debian_version)
# Translate Debian codenames that don't have a version number (yet) into
# according numbers
case "${DEBIAN_RELEASE}" in
bookworm*)
DEBIAN_RELEASE=12
;;
trixie*)
DEBIAN_RELEASE=13
;;
esac
export DEBIAN_RELEASE
# Use an actual variable so that the values do not evaluate as strings,
# and thus as always true.
if [ "$(ngcp-check-active -v)" = 'active' ]; then
NODE_ACTIVE=true
else
NODE_ACTIVE=false
fi
VARS=$(mktemp --tmpdir ngcp-system-tests.XXXXXXXXXX.yaml)
trap 'rm -f "${VARS}"' EXIT
cat >"${VARS}" <<-EOF
SKIP_DNS_CHECK_TEST: ${SKIP_DNS_CHECK_TEST:-false}
NODE_ACTIVE: ${NODE_ACTIVE}
EOF
PLAN='/etc/ngcp-system-tests/goss.yaml'
goss --gossfile "${PLAN}" --vars "${VARS}" \
validate --format "${NGCP_TESTS_MODE}"
;;
esac