From 62a23326620bfcc7092ae283fb70b32aa32ca566 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 18 Dec 2019 17:40:17 +0100 Subject: [PATCH] TT#72351 Add a new helper program to run the tests This new program is a wrapper to make running the tests easier, and it will abstrat all necessary knowledge about the test runner. We also remove the results file generation support, and let our caller handle it as it simplifies the code overall. Change-Id: Iad884429b00a94d5f3c9c3b37db31a523ab3c701 --- debian/ngcp-system-tests.install | 2 +- ngcp-system-tests | 94 ++++++++++++++++++++++++++++++++ testrunner | 36 ------------ 3 files changed, 95 insertions(+), 37 deletions(-) create mode 100755 ngcp-system-tests delete mode 100755 testrunner diff --git a/debian/ngcp-system-tests.install b/debian/ngcp-system-tests.install index 3dd59ff..4e03fd1 100644 --- a/debian/ngcp-system-tests.install +++ b/debian/ngcp-system-tests.install @@ -1,2 +1,2 @@ templates/* /etc/ngcp-config/templates/etc/ngcp-system-tests/ -testrunner /usr/share/ngcp-system-tests/ +ngcp-system-tests /usr/bin/ diff --git a/ngcp-system-tests b/ngcp-system-tests new file mode 100755 index 0000000..dc3b83b --- /dev/null +++ b/ngcp-system-tests @@ -0,0 +1,94 @@ +#!/bin/bash + +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 <...] + +Options: + --mode Operation mode to use. Values: jenkins, tap, prove. + -h, --help Print this help message and exit. +HELP +} + +get_options() { + local _cmdline_opts="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 + bullseye*) + DEBIAN_RELEASE=11 + ;; + esac + export DEBIAN_RELEASE + + # We need to export these, so that goss sees existent variables. + export SKIP_DNS_CHECK_TEST=${SKIP_DNS_CHECK_TEST:-false} + export SKIP_STRICT_HOSTNAME_TEST=${SKIP_STRICT_HOSTNAME_TEST:-false} + + PLAN='/etc/ngcp-system-tests/goss.yaml' + + goss -g "${PLAN}" validate --format "${NGCP_TESTS_MODE}" + ;; +esac diff --git a/testrunner b/testrunner deleted file mode 100755 index 101fcb8..0000000 --- a/testrunner +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -set -e - -REPORT_DIRECTORY='reports/' - -diag() { - echo "$@" 2>&1 -} - -if ! [ -d /etc/ngcp-system-tests/ ]; then - diag "Missing system test suite files, please run 'ngcpcfg build'" - exit 1 -fi - -rm -rf "${REPORT_DIRECTORY}" -mkdir -p "${REPORT_DIRECTORY}" -TAP_RESULTS="${REPORT_DIRECTORY}/goss_results.tap" - -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 - bullseye*) - DEBIAN_RELEASE=11 - ;; -esac -export DEBIAN_RELEASE - -# We need to export these, so that goss sees existent variables. -export SKIP_DNS_CHECK_TEST=${SKIP_DNS_CHECK_TEST:-false} -export SKIP_STRICT_HOSTNAME_TEST=${SKIP_STRICT_HOSTNAME_TEST:-false} - -goss -g "/etc/ngcp-system-tests/goss.yaml" validate --format tap \ - | tee "${TAP_RESULTS}" - -exit "${PIPESTATUS[0]}"