2022-03-15 09:40:01 +00:00
#!/usr/bin/env bash
set -eu
die() {
echo >&2 "$@"
exit 1
}
# shellcheck disable=SC1007
TEST_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
# shellcheck source=./.environment.sh
. "${TEST_DIR}/.environment.sh"
check_bats_core() {
if ! "${TEST_DIR}/lib/bats-core/bin/bats" --version >/dev/null 2>&1; then
die "ERROR: bats-core submodule is required. Please run 'git submodule init; git submodule update' and retry."
fi
}
check_python3() {
if ! command -v python3 >/dev/null; then
die "missing required program 'python3'"
fi
}
2022-04-20 13:05:34 +00:00
check_jq() {
# shellcheck disable=SC2016
if ! command -v jq >/dev/null; then
die "Missing required program 'jq'"
fi
}
2022-03-15 09:40:01 +00:00
check_nc() {
if ! command -v nc >/dev/null; then
die "missing required program 'nc' (package 'netcat-openbsd')"
fi
}
check_yq() {
2022-03-15 14:03:56 +00:00
# shellcheck disable=SC2016
howto_install='You can install it with your favorite package manager (including snap) or with "GO111MODULE=on go get github.com/mikefarah/yq/v4" and add ~/go/bin to $PATH.'
2022-03-15 09:40:01 +00:00
if ! command -v yq >/dev/null; then
2022-03-15 14:03:56 +00:00
die "Missing required program 'yq'. $howto_install"
2022-03-15 09:40:01 +00:00
fi
2022-03-15 14:03:56 +00:00
if ! (yq --version | grep mikefarah >/dev/null); then
die "yq exists but it's not the one we need (mikefarah/yq). $howto_install"
fi
2022-03-15 09:40:01 +00:00
}
check_daemonizer() {
SYSTEM=$(uname -s)
case "${SYSTEM,,}" in
linux)
if ! command -v daemonize >/dev/null; then
die "missing required program 'daemonize' (package 'daemonize')"
fi
;;
freebsd)
if ! command -v daemon >/dev/null; then
die "missing required program 'daemon'"
fi
;;
*)
die "unsupported system: $SYSTEM"
;;
esac
}
2022-04-05 09:00:11 +00:00
check_gocovmerge() {
if ! command -v gocovmerge >/dev/null; then
die "missing required program 'gocovmerge'. You can install it with \"go install github.com/wadey/gocovmerge@latest\""
fi
}
2022-03-15 09:40:01 +00:00
check_bats_core
2022-04-20 13:05:34 +00:00
check_daemonizer
check_jq
2022-03-15 09:40:01 +00:00
check_nc
2022-04-20 13:05:34 +00:00
check_python3
2022-03-15 09:40:01 +00:00
check_yq
2022-04-05 09:00:11 +00:00
if [ -n "${TEST_COVERAGE}" ]; then
check_gocovmerge
fi
2022-03-15 09:40:01 +00:00